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.