创建高度增加的图层-迅速

问题描述 投票:0回答:1

我想制作一个高度增加的自定义滑块,即它的高度从4.0开始到6.0。我已经编写了用于创建图层的代码,但是找不到以这种方式增加其高度的方法。这是我的代码:

let path = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius)
    ctx.addPath(path.cgPath)

    ctx.setFillColor(UIColor.red.cgColor)
    ctx.fillPath()

    let lowerValuePosition = slider.positionForValue(slider.lowerValue)
    let upperValuePosition = slider.positionForValue(slider.upperValue)
    let rect = CGRect(x: 0, y: 0,
                      width: (bounds.width - 36),
                      height: bounds.height)
    ctx.fill(rect)
ios swift calayer
1个回答
0
投票

[您必须在如下所示的子类中重写超类trackRectUISlider方法,并返回所需的范围和大小:

/**
 UISlider Subclass
 */
class CustomSlider: UISlider {

    override func trackRect(forBounds bounds: CGRect) -> CGRect {
        return CGRect(origin: #oigin#, size: CGSize(width: #width#, height: #height#))
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.