"Learn iOS: UI series" Several common controls in iOS. (Uislider,uiswitch,uistepper,uisegmentedcontrol)

Source: Internet
Author: User

One. The slider control (UISlider) effect is as follows

Note: The original effect of the system is as follows

Specific function application:

① Create a Slider control (uislider), set the size of the control, and add it to the window view, and then release

UISlider *slider = [[UISlider alloc] Initwithframe:cgrectmake (20, 30, 280, 100)]; [Self.window Addsubview:slider]; [Slider release];
② set the maximum, minimum, and position of the slider bar at the beginning

    Set maximum value of    [slider setmaximumvalue:10];    Set minimum value 0    [slider setminimumvalue:0];    Slider.value = 5;//The current position is 4. Display effects such as.
③ sets the color of the slider, that is, the color before and after sliding

  Slider.minimumtracktintcolor = [Uicolor orangecolor];//sets the color of the line before moving  slider.maximumtracktintcolor = [UIColor blackcolor];//set the color of the line after the move    
④ Setting the slide control around the picture
Slider.minimumvalueimage = [UIImage imagenamed:@ "[email protected]"];//set scroll bar leftmost picture slider.maximumvalueimage = [ UIImage imagenamed:@ "[email protected]"];//set scroll bar rightmost picture
⑤ set the color of the button when the finger is clicked

Slider.thumbtintcolor = [Uicolor graycolor];//sets the color of the middle button move button
⑥ switch button to picture, normal state

[Slider Setthumbimage:[uiimage imagenamed:@ "[email protected]"] forstate:uicontrolstatenormal];
Response events triggered when the ⑦ is moved

1). The trigger status is: uicontroleventvaluechanged, when triggered, the value of Slider.value will change

2) when the UISlider progress value changes, the function of self is automatically called: Method, and UISlider is passed as the first parameter.

[Slider addtarget:self action: @selector (function:)                                        forcontrolevents:uicontroleventvaluechanged];
⑧ Other Features

UIImage *image = slider.currentmaximumtrackimage;


Two.Switch Control(Uiswitch) effect is as follows


Common operations for switch controls:

① Create a switch control, set the size, add to the view, and release

Uiswitch *switchview = [[Uiswitch alloc] Initwithframe:cgrectmake (50, 100, 280, 100)]; [Self.window Addsubview:switchview]; [SwitchView release];
② Setting the switch status

BOOL setting =  switchview.ison;//get switch status [SwitchView seton:setting animated:yes];//set switch status
③ Setting Colors

  <span style= "FONT-SIZE:14PX;" > Switch Control switch slot <span class= "S6" > </span> color </span>: Replace the green above with orange  Switchview.ontintcolor = [ Uicolor Orangecolor];  Set the color of the button Switchview.thumbtintcolor = [Uicolor redcolor];  <span style= "FONT-SIZE:14PX;" > Color outside of the switch control </span> switchview.tintcolor = [Uicolor Purplecolor];
④ Setting up pictures (no effect in iOS7)

Switchview.onimage = [UIImage imagenamed:@ "[email protected]"];    Switchview.offimage = [UIImage imagenamed:@ "[email protected]"];    
Event handling triggered by the ⑤ switch control

[SwitchView addtarget:self Action: @selector (Switchtag:)                                  forcontrolevents:uicontroleventvaluechanged];
The implementation code is as follows Switchtag:

-(void) Switchtag: (Uiswitch *) Switchtag {             BOOL setting = Switchtag.ison;        [Swithch seton:setting Animated:yes];        if (setting)        {            NSLog (@ "on");        } else        {            NSLog (@ "off");        }  }
Three.Counter Control(Uistepper) effect is as follows


Create the following features

① Create a counter control and release

Uistepper *step = [[Uistepper alloc] init];step.frame = CGRectMake (50, 300, 300, 300); [Self.window Addsubview:step]; [Step release];
② setting the maximum and minimum values, and the values at each addition and subtraction

Each time a minus sign is pressed, value automatically subtracts a certain value (the value is determined by Stepvalue)
Each time the plus sign is pressed, value automatically increments a certain value (the numeric size is determined by Stepvalue)

    Step.maximumvalue = 1;    Step.minimumvalue = 0.1;    Step.stepvalue = 0.1;//value of each increment
③ set whether the loop and whether continuous

Step.continuous = yes;//default is Yesstep.wraps = yes;//Determines whether to loop, that is, to the maximum value and then start from the minimum value.
④ set the color, such as the purple

Step.tintcolor = [Uicolor purplecolor];//sets the color of the button; [Step setbackgroundcolor:[uicolor orangecolor]];//Set background color [step setbackgroundimage:[uiimage imagenamed:@] [email protected] []                                               forstate:uicontrolstatenormal];
⑤ Other operations

Set the background picture, and then a state-(void) SetBackgroundImage: (uiimage*) Image forstate: (uicontrolstate) the state//In a status, get the background picture,-( uiimage*) Backgroundimageforstate: (uicontrolstate) state
⑥ event handling for numeric controls

[Step addtarget:self Action: @selector (Steptag:)                                  forcontrolevents:uicontroleventvaluechanged];//Event Response method implementation-( void) Steptag: (Uistepper *) Stepper {[Self.window viewwithtag:200].alpha = Stepper.value;}
Four.Tab ControlUisegmentedcontrol, as follows

The following actions are implemented:

   Nsarray *arr = [Nsarray arraywithobjects:                       @ "tap", @ "long press", @ "swipe", @ "Pan", @ "pinch", @ "rotate", nil];    Uisegmentedcontrol *segmentedcontrol = [[Uisegmentedcontrol alloc]                                                          Initwithitems:arr];    Segmentedcontrol.frame = CGRectMake (ten, +, +);    [Segmentedcontrol addtarget:self Action: @selector (function:)                              forcontrolevents:uicontroleventvaluechanged];    [Self.window Addsubview:segmentedcontrol];       
Other operations

-(void) Removesegmentatindex: (Nsuinteger) segment animated: (BOOL) animated;-(void) removeallsegments;//output all tabs  <span style= "FONT-SIZE:18PX;" ></span><pre name= "code" class= "OBJC" > Segmentedcontrol.tintcolor = [uicolor orangecolor];//set Border color    <span style= "FONT-SIZE:18PX;" ></span><pre name= "code" class= "OBJC" ><pre name= "code" class= "OBJC" > Nsinteger count  = segmentedcontrol.numberofsegments;//Number of calculations








Learning iOS: UI series Several controls that are common in iOS. (Uislider,uiswitch,uistepper,uisegmentedcontrol)

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.