自定义UISlider thumb icon:如何在拖动时停止拇指图标恢复为默认圆圈图标?

时间:2015-12-17 22:58:28

标签: ios swift uislider

我想将我的UISlider的拇指自定义为我制作的矩形图标。我已经成功地做到了这一点。问题是,当我拖动UISlider时,它会变回默认的圆圈图标。

如何设置拇指图像,即使我拖动它也始终保持为自定义矩形图标?

我已经详细说明了我的代码,并附上了一个链接,以便您可以看到我在下面谈论的内容。

class DrawViewController: UIViewController {    
    var heightSlider: UISlider = UISlider()        
    var fontColor: UIColor = UIColor(red:0.91, green:0.91, blue:0.91, alpha:1.0)
    var barButtonColor: UIColor = UIColor(red:0.03, green:0.25, blue:0.51, alpha:1.0)

    override func viewDidLoad() {
        super.viewDidLoad()

        heightSlider = UISlider(frame: CGRectMake(0, 20, 98, 31))
        heightSlider.minimumTrackTintColor = barButtonColor
        heightSlider.maximumTrackTintColor = fontColor
        heightSlider.thumbTintColor = barButtonColor
        heightSlider.setThumbImage(UIImage(named: "blueSliderThumbHeight")!, forState: .Normal)

        self.view.addSubview(heightSlider)
    } 
}

To see my app/what I'm talking about

1 个答案:

答案 0 :(得分:1)

没关系,我已经弄明白了我的问题!

我只需要删除行heightSlider.thumbTintColor = barButtonColor

class DrawViewController: UIViewController {    
    var heightSlider: UISlider = UISlider()        
    var fontColor: UIColor = UIColor(red:0.91, green:0.91, blue:0.91, alpha:1.0)
    var barButtonColor: UIColor = UIColor(red:0.03, green:0.25, blue:0.51, alpha:1.0)

    override func viewDidLoad() {
        super.viewDidLoad()

        heightSlider = UISlider(frame: CGRectMake(0, 20, 98, 31))
        heightSlider.minimumTrackTintColor = barButtonColor
        heightSlider.maximumTrackTintColor = fontColor
        heightSlider.thumbTintColor = barButtonColor //delete this line!
        heightSlider.setThumbImage(UIImage(named: "blueSliderThumbHeight")!, forState: .Normal)

        self.view.addSubview(heightSlider)
} 

}