let slIDer = UiSlider(frame: CGRectMake(10.0,10.0,(CGRectGetWIDth(self.vIEw.bounds) - 10.0 * 2),20.0))self.vIEw.addSubvIEw(slIDer)slIDer.backgroundcolor = UIcolor.lightGraycolor()
// 设置值(默认值为0.0,且值区间为0.0~1.0)slIDer.minimumValue = 1.0slIDer.maximumValue = 100.0slIDer.setValue(20.0,animated: true)
// 注意:滑动条大小值(minimumTrackTintcolor、maximumTrackTintcolor)颜色与大小值左右两端图标(minimumValueImage、maximumValueImage)不能同时设置,否则图标设置无效slIDer.minimumValueImage = UIImage(named: "normalimage")slIDer.maximumValueImage = UIImage(named: "hightimage")
// 注意:滑动条大小值颜色(minimumTrackTintcolor、maximumTrackTintcolor)与滑动条大小值图标(setMinimumTrackImage、setMaximumTrackImage)不能同时设置,否则先设置的无效// slIDer.setMinimumTrackImage(UIImage(named: "normalimage"),forState: UIControlState.normal)// slIDer.setMaximumTrackImage(UIImage(named: "hightimage"),forState: UIControlState.normal) slIDer.minimumTrackTintcolor = UIcolor.yellowcolor()slIDer.maximumTrackTintcolor = UIcolor.redcolor()
// 滑动块颜色、或图标设置(注意:两者不能同时设置,否则先设置的无效。另外,默认thumb块比较大,可通过设置thumbImage的方法改变thumb大小)slIDer.thumbTintcolor = UIcolor.greencolor()slIDer.setThumbImage(UIImage(named: "hightimage"),forState: UIControlState.normal)slIDer.setThumbImage(UIImage(named: "hightimage"),forState: UIControlState.Highlighted)
// 滑块滑动停止后才触发ValueChanged事件slIDer.continuous = false// 响应事件slIDer.addTarget(self,action: Selector("slIDerValueChange:"),forControlEvents: UIControlEvents.ValueChanged)
let label = UILabel(frame: CGRectMake(10.0,(CGRectGetMinY(slIDer.frame) + CGRectGetHeight(slIDer.bounds) + 10.0),(CGRectGetWIDth(self.vIEw.frame) - 10.0 * 2),30.0))self.vIEw.addSubvIEw(label)label.backgroundcolor = UIcolor.yellowcolor()label.textcolor = UIcolor.redcolor()label.tag = 1000let value = slIDer.valuelabel.text = String(format: "slIDer当前值是:%.2f",arguments: [value])
// MARK: - slIDerValueChangefunc slIDerValueChange(slIDer:UiSlider){ let value = slIDer.value let label:UILabel = self.vIEw.vIEwWithTag(1000) as! UILabel label.text = String(format: "slIDer当前值是:%.2f",arguments: [value]) print("slIDer当前值是:\(value)")}
总结
以上是内存溢出为你收集整理的swift中UISlider的使用全部内容,希望文章能够帮你解决swift中UISlider的使用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)