Swift滑块(UISlider)的用法

import UIKit

class ViewController: UIViewController        ,UITextFieldDelegate,UITextViewDelegate,UIActionSheet  Delegate,UIAlertViewDelegate{
override func viewDidLoad() {
    super.viewDidLoad()

let slider = UISlider ()
    slider.frame = CGRectMake(10, 630, 200, 30)
    slider.maximumValue = 1
    slider.minimumValue = 0
    slider.value = 0.8
    self.view.addSubview(slider)
    //设置滑块的值,同时有动画
    slider.setValue(0.1, animated: true)
    //滑块值改变响应
    slider.continuous = true
    slider.addTarget(self, action: "sliderDidChange:", forControlEvents: UIControlEvents.ValueChanged)
    //滑块左右两边槽的颜色
    slider.maximumTrackTintColor = UIColor.greenColor()//右槽颜色
    slider.minimumTrackTintColor = UIColor.redColor()//左槽颜色
    //
    slider.minimumValueImage = UIImage(named: "tutu")//左图
    slider.maximumValueImage = UIImage(named: "tutu")//右图
    //设置滑块左右边部分的图片
    slider.setMaximumTrackImage(UIImage(named: "tutu"), forState: UIControlState.Normal)
    slider.setMinimumTrackImage(UIImage(named: "pianpian"), forState: UIControlState.Normal)
    //设置滑块图片
    slider.setThumbImage(UIImage(named: "huakuan"), forState: UIControlState.Normal)
//        //设置滑块右边部分的图片-使用三宫格缩放(左右14像素不变,中间缩放)
//        let imageTrackRight = UIImage(named: "ruru")
//        let imgRight = imageTrackRight!.stretchableImageWithLeftCapWidth(14, topCapHeight: 0)
//        slider.setMaximumTrackImage(imgRight, forState: UIControlState.Normal)


}

 func sliderDidChange(slider:UISlider){
    print(slider.value)
    
    }

}

你可能感兴趣的:(Swift滑块(UISlider)的用法)