提问者:小点点

创建一个增加高度的图层-快速


我想做一个自定义的滑块,有增加的高度,即它的高度从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)

共1个答案

匿名用户

您必须重写子类中超类uislidertrackrect方法,如下所示,并返回所需的边界和大小:

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

    override func trackRect(forBounds bounds: CGRect) -> CGRect {
        return CGRect(origin: #oigin#, size: CGSize(width: #width#, height: #height#))
    }
}