Swift Practice---UISlider

Source: Internet
Author: User

Import UIKit

Class Viewcontroller:uiviewcontroller {

Override Func Viewdidload () {

Super.viewdidload ()

Let slider = Uislider.init (Frame:CGRect.init (x:0, y:0, width:300, height:50))

Slider.center = Self.view.center

Slider.minimumvalue = 0

Slider.maximumvalue = 1

Slider.value = 0.5

Self.view.addSubview (Slider)

Animate the value of the Set slider

Slider.setvalue (0.5, animated:true)

Slider Value change response

Slider.iscontinuous = false///slider will not trigger valuechanged event after sliding stop

Slider.addtarget (Self, Action: #selector (Sliderchange (slider:)), for:. valuechanged)

The color of the left and right side slots of the slider

Slider.minimumtracktintcolor = uicolor.red

Slider.maximumtracktintcolor = Uicolor.green

Add an icon to the sides of the slider behind the Groove line

Slider.minimumvalueimage=uiimage (named: "2")//Left icon

Slider.maximumvalueimage=uiimage (named: "2")//Right icon

Set the picture of the slider

Slider.setthumbimage (UIImage (named: "2"), For:.normal)

}

Func Sliderchange (Slider:uislider) {

Print (Slider.value)

}

Override Func didreceivememorywarning () {

Super.didreceivememorywarning ()

Dispose of any resources the can be recreated.

}

}

Swift Practice---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.