1 //first method of Creation2Uisegmentedcontrol *seg = [[Uisegmentedcontrol alloc]initwithitems:@[@"1",@"2",@"3"]];3Seg.frame = CGRectMake ( +, -, -, -);4 5[Seg insertsegmentwithimage:[uiimage imagenamed:@"Picture name"] Atindex:4Animated:yes];//set a picture for a paragraph (the picture is transparent with a border to be fully displayed, other pictures can not be fully displayed)6UIImage *image = [seg Imageforsegmentatindex:2];//get a picture of a paragraph7NSLog (@"Image:%@", image);8NSString *str = [seg Titleforsegmentatindex:1];//get the title of a paragraph9NSLog (@ "The first few:%zi", Segment.selectedsegmentindex);//Get the number of the current clickTenNSLog (@"title:%@", str); One[Seg SetWidth: -Forsegmentatindex:1];//set the width of a paragraph A[Seg Setenabled:yes];//sets whether the whole is activated; -[Seg Setenabled:yes Forsegmentatindex:2];//set whether a segment is active -Seg.selectedsegmentindex =1;//set a segment as the default check theNSLog (@"%zi", Seg.selectedsegmentindex);//gets the currently selected segment; -Seg.tintcolor = [Uicolor Purplecolor];//set border and selected color; -[Seg setbackgroundimage:[uiimage imagenamed:@"Picture name"] Forstate:uicontrolstatenormal Barmetrics:uibarmetricsdefault];//set the overall background picture - + //Binding Listener Events - [SEG addtarget:self Action: @selector (method Name:) forcontrolevents:uicontroleventvaluechanged]; + [Self.view addsubview:seg]; A at //second method of creation -Uisegmentedcontrol *SEG2 = [[Uisegmentedcontrol alloc]initwithframe:cgrectmake ( +, -, -, -)]; -[SEG2 Insertsegmentwithtitle:@"1"Atindex:1Animated:yes]; -[SEG2 Insertsegmentwithtitle:@"2"Atindex:2Animated:yes]; -[SEG2 Removesegmentatindex:1Animated:yes];//Remove a segment -NSLog (@"%zi", seg2.numberofsegments);//get number of segments in [Self.view ADDSUBVIEW:SEG2]; - to } + --(void) Myswitch the { *Uiswitch *SWI = (Uiswitch *) [Self.view Viewwithtag:1]; $NSLog (@"%d", Swi.ison);Panax Notoginseng -}
A summary of the usage of ios--ui articles--uisegmentedcontrol