Uiswitch (Switch control), Uisegmentedcontrol (segmented control)

Source: Internet
Author: User

First, Uiswitch1. Initialize Uiswitch *s1 = [[Uiswitch alloc]initwithframe:cgrectmake (50, 170, 100, 200)]; 2. Set related Properties S1.ontintcolor = [Uicolor bluecolor];s1.tintcolor = [Uicolor greencolor];s1.thumbtintcolor = [UIColor RedColor] ; 3, set switch state S1.on = yes;4, add event [S1 addtarget:self Action: @selector (myswitch) forControlEvents: Uicontroleventvaluechanged];
[S1 addtarget:self Action: @selector (myswitch:) forcontrolevents:uicontroleventvaluechanged]; 5. Join the parent View [Self.view ADDSUBVIEW:S1]; Method of adding an event-(void) myswitch{
NSLog (@ "triggered the Change Method");
}
-(void) Myswitch: (Uiswitch *) s{
Uiswitch *S2 = (Uiswitch *) [Self.view viewwithtag:1];
NSLog (@ "%d", S.ison);
NSLog (@ "%d", S2.ison);} Second, UISegmentedControl1, Initialize (1) mode 1Uisegmentedcontrol *seg =[[uisegmentedcontrol alloc] initwithframe:cgrectmake ((+, +, + )];//The initialization size when created, but does not set the parameters for each segment (2) Mode 2uisegmentedcontrol *seg1 = [[uisegmentedcontrol alloc] initwithitems:@[@ "1" ,@ "2",@ "3"]];//The initial number of segments and title directly at initialization 2. Setting related properties(1) [Seg settitle:@ "My " forsegmentatindex:0];//Set the title text for a paragraph (2) [Seg setimage: [UIImage imagenamed:@ "Lanzuan"] forsegmentatindex: 0];//Set the image of a segment, note that both the title and the image can have only one (3) [Seg insertsegmentwithtitle:@ "2" atindex:0 animated:NO] ;// Insert a segment titled 2 in the subscript 0 position , paying attention to the reasonableness of the subscript (4) [Seg insertsegmentwithimage: [UIImage imagenamed:@ "1.png"] atindex :0 animated:NO];// Inserts a segment at the subscript 0 position to set its picture (5)seg. Tintcolor = [uicolor whitecolor];//set segment border color and text /Picture color (6) [Seg removesegmentatindex:0 animated:YES];//Removal of a segment (7) [seg removeallsegments];//removal of all segments (8)seg. numberofsegments;//Remove a segment (9) seg. selectedsegmentindex = 0;//Select the selected excerpt by default (10)nsstring *str = [seg titleforsegmentatindex:0];//get title of a paragraph (11)UIImage *image = [seg imageforsegmentatindex:0];//Get a picture of a segment (12)[seg setwidth: forsegmentatindex:0];//Sets the width of a segment (13)[seg setbackgroundimage: [UIImage imagenamed:@ "Imsend"] forstate: uicontrolstatenormal barmetrics: uibarmetricsdefault];//Set the normal background image (14)[seg setbackgroundimage: [UIImage imagenamed:@ "Logoin_6"] forstate: uicontrolstateselected barmetrics:uibarmetricsdefault];//Set the selected background image (15)[seg addTarget:self action:@selector(change:) forcontrolevents:uicontroleventvaluechanged];//binding Listener event Uisegmentedcontrol *segment1 = [[uisegmentedcontrolalloc]initwithitems:@[@ "Hello", @ "Welcome", @ "join"]];// The initial number of segments and title are given directly when initializing
Segment1.frame = CGRectMake (90, 240, 200, 50);//Initialization size

[Segment1 insertsegmentwithimage:[uiimage imagenamed:@ "3.jpg"] atindex:1 animated:yes];//Insert picture and allow animation

NSLog (@ "Number of segments:%zi", segment1.numberofsegments);//Gets the number of segments
[Segment1 settitle:@ "we" forsegmentatindex:0];
NSString *str = [Segment1 titleforsegmentatindex:1];//get the title of the picture, note that the position to be inserted in the picture corresponds to

NSLog (@ "picture title =%@", str);
UIImage *image = [Segment1 imageforsegmentatindex:1];
NSLog (@ "Picture =%@", image);

[Segment1 setwidth:100 forsegmentatindex:0];//Sets the width of a segment
[Segment1 setenabled:no forsegmentatindex:0];//Sets whether a segment is activated
[Segment1 setenabled:no];//Whole is not activated

Segment1.selectedsegmentindex = 1;//Sets the default check
NSLog (@ "%zi", segment1.selectedsegmentindex);//Gets the currently selected segment
Segment1.tintcolor = [Uicolor greencolor];//border and selected color
[Segment1 setbackgroundimage:[uiimage imagenamed:@ "3"] forstate:uicontrolstatenormal barmetrics: Uibarmetricsdefault];
UIControlStateNormal, Uibarmetricsdefault set as the default is good [segment1 addtarget:self action: @selector (Segmentchange) Forcontrolevents:uicontroleventvaluechanged]; Trigger Event-(void) segmentchange{
NSLog (@ "segment is clicked");} [Self.view Addsubview:segment1];
Uisegmentedcontrol *s = [[Uisegmentedcontrol alloc]initwithframe:cgrectmake (50, 400, 100, 50)];
[s insertsegmentwithtitle:@ "segment" Atindex:3 Animated:yes];
[s insertsegmentwithtitle:@ "function" atindex:0 animated:yes];//increase//[s removesegmentatindex:0 animated:yes];//Remove [self.vi EW addsubview:s];

Uiswitch (Switch control), Uisegmentedcontrol (segmented control)

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.