标签:target gre 动画 err get add load() ted uiimage
import UIKit
var imageView:UIImageView!
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
//创建Slider
let slider = UISlider(frame: CGRect(x: 50, y: 250, width: 300, height: 50))
//最小值
slider.minimumValue = 0
//最大值
slider.maximumValue = 1
//设置默认值
slider.value = 0.1
//设置Slider值,并t有动画效果
slider.setValue(0.5, animated: true)
//设置Slider两边槽的颜色
slider.minimumTrackTintColor = UIColor.red
slider.maximumTrackTintColor = UIColor.green
//添加两边槽图片
slider.minimumValueImage = UIImage(named: "image")
slider.maximumValueImage = UIImage(named: "image1")
//设置Slider组件图片
slider.setMaximumTrackImage(UIImage(named:"Maximage1"), for: .normal)
slider.setMinimumTrackImage(UIImage(named:"MinImage2"), for: .normal)
slider.setThumbImage(UIImage(named: "thumInage"), for: .normal)
//使用三宫格缩放
let image = UIImage(named: "image3")?.stretchableImage(withLeftCapWidth: 14, topCapHeight: 0)//左右像素为14px,中间缩放
slider.setMaximumTrackImage(image, for: .normal)
//Slider值改变响应
slider.isContinuous = false//设置在停止滑动时才出发响应事件
slider.addTarget(self, action: #selector(ViewController.SliderChanged), for: .valueChanged)
//添加到视图中
self.view.addSubview(slider)
}
@objc func SliderChanged(_ slider:UISlider)
{
print(slider.value)
}
}
标签:target gre 动画 err get add load() ted uiimage
原文地址:https://www.cnblogs.com/iOS-Development/p/10228324.html