1、UISlider
let slider =UISlider(frame: CGRect(x: 30, y: 100, width: 300, height: 50)) slider.center = self.view.center slider.minimumValue = 0 slider.maximumValue = 1 // slider.value = 0.5 self.view.addSubview(slider) slider.setValue(0.8, animated: true) slider.isContinuous = false//滑块滑动停止后才触发ValueChange事件 slider.addTarget(self, action: #selector(sliderDidchange(slider:)), for: .valueChanged) slider.minimumTrackTintColor = UIColor.red//左边槽的颜色 slider.maximumTrackTintColor = UIColor.green //右边槽的颜色 slider.minimumValueImage = UIImage(named: "baibai")//左边图片 slider.maximumValueImage = UIImage(named: "baibai")//右边图片 //自定义滑块组件图片 //设置滑块右边部分的图片 slider.setMaximumTrackImage(UIImage(named: "baibai"), for:.normal) //设置滑块左边部分的图片 slider.setMinimumTrackImage(UIImage(named: "baibai"), for: .normal) //设置滑块的图片 slider.setThumbImage(UIImage(named: "baibai"), for: .normal) //设置滑块右边部分的图片 - 使用三宫格缩放(左右像素不变,中间缩放) let imgTrackRight = UIImage(named: "baibai") let imgRight = imgTrackRight!.stretchableImage(withLeftCapWidth: 14, topCapHeight: 0) slider.setMaximumTrackImage(imgRight, for: .normal)
请发表评论