Use of Swift-slider (UISlider)

Source: Internet
Author: User

1, the creation of the slider

123456 varslider=UISlider(frame:CGRectMake(0,0,300,50))slider.center=self.view.centerslider.minimumValue=0  //最小值slider.maximumValue=1  //最大值slider.value=0.5  //当前默认值self.view.addSubview(slider)

2, set the value of the slider, with animation

1 slider.setValue(0.8,animated:true)

3, slider value change response

123456 slider.continuous= false   //slide stops before triggering valuechanged events slider.addtarget ( self "Sliderdidchange:" uicontrolevents valuechanged )  func Sliderdidchange (slider: uislider Code class= "Swift Spaces" >     println (slider.value) }

4, the color of the left and right side slots of the slider

12 slider.minimumTrackTintColor=UIColor.redColor()  //左边槽的颜色slider.maximumTrackTintColor=UIColor.greenColor() //右边槽的颜色

5, add icon on both sides of the slider behind the slot line

12 slider.minimumValueImage=UIImage(named:"voice+"//左边图标slider.maximumValueImage=UIImage(named:"voice-"//右边图标

6, custom slider component picture

123456 //设置滑块右边部分的图片slider.setMaximumTrackImage(UIImage(named:"slider_max"),forState:UIControlState.Normal)//设置滑块左边部分的图片slider.setMinimumTrackImage(UIImage(named:"slider_min"),forState:UIControlState.Normal)//设置滑块的图片slider.setThumbImage(UIImage(named:"slider_thumb"),forState:UIControlState.Normal)

1234 //设置滑块右边部分的图片-使用三宫格缩放(左右14像素不变,中间缩放)letimgTrackRight = UIImage(named:"slider_max")letimgRight = imgTrackRight!.stretchableImageWithLeftCapWidth(14, topCapHeight:0)slider.setMaximumTrackImage(imgRight, forState:UIControlState.Normal)

Use of Swift-slider (uislider)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.