iOS自定义滑块从两端删除最小和最大空间

时间:2018-10-25 10:44:11

标签: ios swift uislider

我正在尝试使用制作自定义滑块

class MySlider: UISlider {

    override func trackRect(forBounds bounds: CGRect) -> CGRect {
        let customBounds = CGRect(origin: bounds.origin, size: CGSize(width: bounds.size.width, height: 5.0))
        super.trackRect(forBounds: customBounds)
        return customBounds
    }
}

更新了故事板上的拇指/最大/最小色度 enter image description here

问题是需要从两端移除最小和最大空间,如图所示。我该怎么做? enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

我无需子类即可实现此目标

通过IB设置缩略图色调Default

@IBOutlet weak var slider: MySlider!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        let size = CGSize(width: 1 , height: 1)
        UIGraphicsBeginImageContext(size)
        let finalImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        slider.setThumbImage(finalImage, for: .normal)
    }