Use of Uisegmentedcontrol

Source: Internet
Author: User

Directly on the code:
creation of//uisegmentedcontrol objects    The //parameter array is an array of strings that represent the headings of each segment, and the number of objects in the array determines the number of segments.     Uisegmentedcontrol*segmentcontrol = [[UisegmentedcontrolAlloc] initwithitems:@[@"Yellow", @"Red", @"(~"~) ~zz ", @"?"]]; Segmentcontrol. Frame= CGRectMake ( -, -, Cgrectgetwidth ( Self. View. Bounds) - -, +);//Set subscript for selected segmentsSegmentcontrol. Selectedsegmentindex=1;//When the default selected subscript is set, in order to be able to respond to the method, you need to call the corresponding method manually, and the current segmented space object as a parameter into the method, the inside of the method will be based on the sub-control of the selected subscript to make the operation. [ SelfHandlesegmentaction:segmentcontrol];//modify its appearance color by setting the surface shading of the segmented control, and the selected color changes as the border color changesSegmentcontrol. Tintcolor= [UicolorBlackcolor];//Background color//Segmentcontrol.backgroundcolor = [Uicolor browncolor];    //When adding a picture to a segment, you need to change the render mode of the image object to the original rendering mode, otherwise the picture will follow the control's tintcolor into a solid color block.    UIImage*firstimage = [[UIImageimagenamed:@"2"] imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];//Set the picture for the specified segmented subscript[Segmentcontrol setimage:firstimage Forsegmentatindex:0];//Bind response method[Segmentcontrol AddTarget: SelfAction@selector(handlesegmentaction:) forcontrolevents:uicontroleventvaluechanged]; [ Self. ViewAddsubview:segmentcontrol]; [Segmentcontrol release];-(void) Handlesegmentaction: (Uisegmentedcontrol*) Sender {Switch(Sender. Selectedsegmentindex) { Case 0: Self. View. BackgroundColor= [UicolorYellowcolor];NSLog(@"Yellow"); Break; Case 1: Self. View. BackgroundColor= [UicolorRedcolor];NSLog(@"Red"); Break; Case 2: Self. View. BackgroundColor= [UicolorBluecolor];NSLog(@"Blue"); Break; Case 3: Self. View. BackgroundColor= [UicolorGreencolor];NSLog(@"Green"); Break; }NSLog( @'%s ', __function__);}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Use of 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.