IOS growth path-Segmentarray Control

Source: Internet
Author: User

Use the code to create the Segmentarray control and set its attributes:

/* Segmentarray. h */# import <UIKit/UIKit. h> @ interface segmentarray: UIViewController {// create control object UISegmentedControl * segment;} @ property (nonatomic, retain) UISegmentedControl * segment; @ end

Initialize and set attribute values in the. m file

-(Void) viewdidload {[Super viewdidload]; // create an array to store the title nsarray * segmentarray = [[nsarray alloc] initwithobjects: @ "1 ", @ "2", @ "3", @ "4", nil]; // initialize the segmentcontrol object and add the title to self. segment = [[uisegmentedcontrol alloc] initwithitems: segmentarray]; // after use, release the nsarray object [segmentarray release]; // locate, set the position added to the interface and its width/height self. segment. frame = cgrectmake (40, 60,120, 40); // you can specify the segmentcontrol style self. segment. segmentedcontrolstyle = custom;/* Four control styles uisegmentedcontrolstyleplain, // large plain controls, // large bordered uisegmentedcontrolstylebar, // small button/nav bar style. tintable uisegmentedcontrolstylebezeled, // large bezeled style. tintable * // set the initial default value and Set Self according to the index value. segment. selectedsegmentindex = 2; // Add the control to view [self. view addsubview: Self. segment]; // release the segmentcontrol object [segment release];}

Related Article

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.