码迷,mamicode.com
首页 > 编程语言 > 详细

Swift - UISlider

时间:2019-01-06 13:34:52      阅读:217      评论:0      收藏:0      [点我收藏+]

标签: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)
    }
}

Swift - UISlider

标签:target   gre   动画   err   get   add   load()   ted   uiimage   

原文地址:https://www.cnblogs.com/iOS-Development/p/10228324.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!