IOS Study Notes (7) Basic concepts and usage of UISegmentedControl

Source: Internet
Author: User

IOS learning notes (7) Basic concepts and usage of UISegmentedControl segment controls (blog address: http://blog.csdn.net/developer_jiangqq)

Author: hmjiangqq

Email: jiangqqlmj@163.com

UISegmentedControl

First, let's take a look at the official website introduction:


AUISegmentedControlObject is a horizontal control made of multiple segments, each segment functioning as a discrete button. A segmented control affords a compact means to group together a number of controls.

A segmented control can display a title (NSStringObject) or an image (UIImageObject).UISegmentedControlObject automatically resizes segments to fit proportionally within their superview unless they have a specific width set. When you add and remove segments, you can request that the action be animated with sliding and fading effects.

The segment control is a selection control, which is similar to the single-choice button in Windows and consists of two ends or more segments,

Each segment is equivalent to an independent button. This control generally has two styles: Plain & Bordered style and Bar style,

The Bordered style adds a border on the Plain style. Plain and Bordered style. You can set text for each section.

It is relatively narrow compared with adding an image. Bar style. We generally do not place images in it.

Common attributes and methods are as follows:


The instance code is as follows:

-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions {self. window = [[[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds] autorelease]; // Override point for customization after application launch. self. window. backgroundColor = [UIColor whiteColor]; NSArray * array = @ [@ "Search", @ "select", @ "video", @ "image"]; UISegmentedControl * segmentControl = [[UISegmentedControl alloc] initWithItems: array]; segmentControl. segmentedControlStyle = UISegmentedControlStyleBordered; // you can specify the segmentControl position. frame = CGRectMake (60,100,200, 40); // segmentControl is selected by default. selectedSegmentIndex = 1; // sets the background color segmentControl. tintColor = [UIColor greenColor]; // sets the listening event [segmentControl addTarget: self action: @ selector (change :) forControlEvents: UIControlEventValueChanged]; [self. window addSubview: segmentControl]; [segmentControl release]; [self. window makeKeyAndVisible]; return YES;}-(void) change :( UISegmentedControl *) segmentControl {NSLog (@ "segmentControl % d", segmentControl. selectedSegmentIndex );}
Run:



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.