iOS learning-Other common controls

Source: Internet
Author: User

1 //2 //VIEWCONTROLLER.M3 //Other common Controls4 //5 //Created by Big Huan on 16/1/25.6 //copyright©2016 year BJSXT. All rights reserved.7 //8 9 #import "ViewController.h"Ten  One @interfaceViewcontroller () A  -@property (Weak, nonatomic) Iboutlet UILabel *Switchlabel; -  the @end -  - @implementationViewcontroller -  +- (void) Viewdidload { - [Super Viewdidload]; +      A //[self createswitch]; at //[self createsegment]; - //[self createslider]; -      -      -  - } in  -- (void) Createslider { to      +     //Sliding block -UISlider * slider = [[UISlider alloc] Initwithframe:cgrectmake ( -, -, Cgrectgetwidth (Self.view.frame)- +, - )]; the     //Slider.backgroundcolor = [Uicolor graycolor]; *Slider.minimumvalue =Ten; $Slider.maximumvalue = -;Panax Notoginseng     //Small track Color -Slider.minimumtracktintcolor =[Uicolor Greencolor]; the     //Large-value track color +Slider.maximumtracktintcolor =[Uicolor Redcolor]; A     //Drag the color of the circle theSlider.thumbtintcolor =[Uicolor Yellowcolor]; +Slider.value = -; -     //can I call Valuechange continuously $     //slider.continuous = NO; $     //add a picture to the smallest end -Slider.minimumvalueimage = [UIImage imagenamed:@"Apply_sex_normal"]; -     //Max side Add picture theSlider.maximumvalueimage = [UIImage imagenamed:@"apply_sex_selected"]; -     Wuyi     //picture of the slider the //[Slider setthumbimage:[uiimage imagenamed:@ "apply_sex_selected"] forstate:uicontrolstatenormal]; - //    //pictures of smaller end tracks Wu //[Slider setminimumtrackimage:[uiimage imagenamed:@ "Apply_sex_normal"] forstate:uicontrolstatenormal]; -      About [Slider addtarget:self action: @selector (slideraction:) forcontrolevents:uicontroleventvaluechanged]; $ [Self.view Addsubview:slider]; -      - } -  A- (void) Slideraction: (UISlider *) Slider { +      theSelf.switchLabel.font =[Uifont SystemFontOfSize:slider.value]; - } $  the- (void) createsegment { the      theNsarray * array = @[@"Red",@"Green",@"Yellow",@"Blue",@"Orange"]; the      -     //Segment Selector inUisegmentedcontrol * segment =[[Uisegmentedcontrol alloc] initwithitems:array]; theSegment.frame = CGRectMake ( -, Cgrectgetheight (Self.view.frame)- -, Cgrectgetwidth (Self.view.frame)- +, -); the     //Whether you can select AboutSegment.momentary =NO; the     //text fit to width theSegment.apportionssegmentwidthsbycontent =NO; the     //Inserting a satin +     //[Segment insertsegmentwithtitle:@ "Apple" atindex:1 Animated:yes]; -     //[Segment Setimage:[uiimage imagenamed:@ "Onimage"] forsegmentatindex:2]; theSegment.tintcolor =[Uicolor Orangecolor];Bayi [Segment Addtarget:self action: @selector (segmentaction:) forcontrolevents:uicontroleventvaluechanged]; the [Self.view addsubview:segment]; the      - } -  the- (void) Segmentaction: (Uisegmentedcontrol *) Segment { the      theNsinteger index =Segment.selectedsegmentindex; the     Switch(index) { -          Case 0: theSelf.view.backgroundColor =[Uicolor Redcolor]; the              Break; the          Case 1:94Self.view.backgroundColor =[Uicolor Greencolor]; the              Break; the          Case 2: theSelf.view.backgroundColor =[Uicolor Yellowcolor];98              Break; About          Case 3: -Self.view.backgroundColor =[Uicolor Bluecolor];101              Break;102          Case 4:103Self.view.backgroundColor =[Uicolor Orangecolor];104              Break; the         default:106              Break;107     }108 }109  the- (void) Createswitch {111      the     //Switch113Uiswitch * SW = [[Uiswitch alloc] Initwithframe:cgrectmake ( -, -,0,0)]; the     //status of the switch theSw.on =YES; the     //color When the switch is turned on117Sw.ontintcolor =[Uicolor Redcolor];118     //color When the switch is off119Sw.tintcolor =[Uicolor Cyancolor]; -     //the color of the switch circle121Sw.thumbtintcolor =[Uicolor Yellowcolor];122     123     //Suitable for iOS6.0124     //sw.onimage = [UIImage imagenamed:@ "Onimage"]; the     //sw.offimage = [UIImage imagenamed:@ "Onimage"];126     127     //uicontroleventvaluechanged -     129 [SW addtarget:self Action: @selector (switchaction:) forcontrolevents:uicontroleventvaluechanged]; the     131 [Self.view ADDSUBVIEW:SW]; the     133 }134 135- (void) Switchaction: (Uiswitch *) SW {136     137     if(sw.on) {138Self.switchLabel.hidden =NO;139}Else { $Self.switchLabel.hidden =YES;141     }142     143 }144 145 @end

iOS learning-Other common controls

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.