UI_UISegmentedControl, uisegmentedcontrol

Source: Internet
Author: User

UI_UISegmentedControl, uisegmentedcontrol
Create controls

-(Void) createSegmentControl {UISegmentedControl * segmentedControl = [[UISegmentedControl alloc] initWithItems: @ [@ "all", @ "category", @ "in progress"]; segmentedControl. frame = CGRectMake (80, 30,180, 30); // The first segmentedControl is selected by default. selectedSegmentIndex = 0; // change the control and font color [segmentedControl setTintColor: [UIColor redColor]; // change the title of a segmentedControl [segmentedControl setTitle: @ "not all" forSegmentAtIndex: 0]; // set the image [segmentedControl setImage: [UIImage imageNamed: @ "2.png"] forSegmentAtIndex: 2]; // obtain the total number of nslogs (@ "% lu buttons in total", segmentedControl. numberOfSegments); [self addSubview: segmentedControl]; [segmentedControl release]; // bind a click event (most important) to segmentedControl addTarget: self action: @ selector (segmentedControlAction :) forControlEvents: UIControlEventValueChanged];}
Click events
-(Void) segmentedControlAction :( UISegmentedControl *) sender {// you can use selectedSegmentIndex to determine which Segment/* if (sender. selectedSegmentIndex = 0) {NSLog (@ "all");} else if (sender. selectedSegmentIndex = 1) {NSLog (@ "category");} else if (sender. selectedSegmentIndex = 2) {NSLog (@ "in progress");} */switch (sender. selectedSegmentIndex) {case 0: {NSLog (@ "all"); break;} case 1: NSLog (@ "category"); break; case 2: NSLog (@ "in progress"); break; default: break ;}}

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.