[Swift Learning] Uikit Learn the use of slider control UISlider

Source: Internet
Author: User
Tags uikit

Uikit Learn the use of slider control UISlider


Slider:

Sliders enable users to interactively modify some adjustable the value in a app, such as speaker volume or screen brightness.


UISlider:

A UISlider object is a visual control used to select a single value from a continuous range of values. Sliders is always displayed as horizontal bars. An indicator, or thumb, notes the current value of the slider and can is moved by the user to the setting.


UISlider The creation of the control:

(1) using Ctrl+drag drag-and-drop method in Stroyboard to create

(2) Code creation

Create a slider control let Slider=uislider (Frame:cgrectmake (0,0,300,50))//Set sliderslider.center=  Self.view.centerslider.minimumvalue=0//min slider.maximumvalue=1//MAX slider.value=0.5//current default Self.view.addSubview (Slider)


import uikitclass viewcontroller: uiviewcontroller {    override  Func viewdidload ()  {        super.viewdidload ()          // do any additional setup after loading  the view, typically from a nib.                 let slider=uislider (Frame:cgrectmake (0,0,300,50))          slider.center=self.view.center         slider.minimumvalue=0  //Minimum Value          slider.maximumvalue=1  //Maximum Value         slider.value=0.5   //Current default value                  slider.continuous=false &nbsp///slide stops before triggering valuechanged events                  //Add response Event         slider.addtarget (self, action: " Sliderdidchanged: ",  forcontrolevents:uicontrolevents.valuechanged)                  //set the color of the side slots          slider.minimumtracktintcolor=uicolor.redcolor ()    //left slot color, default is blue          slider.maximumtracktintcolor=uicolor.browncolor ()  //right slot color, default is gray                  self.view.addsubview (slider)             }         //Response Event Function     func sliderdidchanged (slider:UISlider) {                 //value of output control          Print (Slider.value)     }        override func  didreceivememorywarning ()  {         Super.didreceivememorywarning ()         // Dispose of  any resources that can be recreated.    }}



[Swift Learning] Uikit Learn the use of slider control 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.