gpt4 book ai didi

ios - 快速更改多种颜色的 UISlider 轨道颜色?

转载 作者:搜寻专家 更新时间:2023-11-01 06:19:01 25 4
gpt4 key购买 nike

我可以使用我获得的值 (sender.value) 来改变 slider 移动时的颜色吗?随着 slider 的移动,我正在尝试将颜色从绿色更改为黄色再更改为红色。请 swift 帮忙谢谢!

let brokeSlider = UISlider(frame:CGRectMake(5, 440, 355, 20))
brokeSlider.minimumValue = 0
brokeSlider.maximumValue = 1
brokeSlider.continuous = true
brokeSlider.tintColor = UIColor.blackColor()
brokeSlider.value = 0
brokeSlider.addTarget(self, action: #selector(AnnotationPhotoWidget.sliderValueDidChange(_:)), forControlEvents: .ValueChanged)
self.view.addSubview(brokeSlider)

func sliderValueDidChange(sender:UISlider) {
print("value--\(sender.value)")
}

最佳答案

试试下面的代码:

func sliderValueDidChange(sender:UISlider) {
print("value--\(sender.value)")
if sender.value <= 0.3 {
brokeSlider.minimumTrackTintColor = UIColor.green
} else if sender.value > 0.3 && sender.value <= 0.6 {
brokeSlider.minimumTrackTintColor = UIColor.yellow
} else {
brokeSlider.minimumTrackTintColor = UIColor.red
}
}

关于ios - 快速更改多种颜色的 UISlider 轨道颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37888667/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com