使用UISegmentedControl从一组或一组值中选择
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用UISegmentedControl从一组或一组值中选择相关的知识,希望对你有一定的参考价值。
The UISegmentedControl consists of a horizontal control divided into segments. Segmented controls are useful for allowing users to pick from a group or set of values.Each segment functions as its own button. By default, selecting a segment will deselect the others in the control (much as a radio button does in html). You can alter this behavior by setting the "momentary" property.
- (void)segmentClick:(id)sender { NSLog(@"you selected segment %d",[sender selectedSegmentIndex]); } - (void)viewDidLoad { [super viewDidLoad]; UISegmentedControl *mySegment = [[UISegmentedControl alloc] initWithItems:arrSegments]; CGRect segmentRect = CGRectMake(10,50,300,40); [mySegment setFrame:segmentRect]; [mySegment addTarget:self action:@selector(segmentClick:) forControlEvents:UIControlEventValueChanged]; [mySegment setSegmentedControlStyle:UISegmentedControlStyleBar]; [mySegment setTintColor:[UIColor darkGrayColor]]; // mySegment.momentary = YES; // allow multiple multiple selection //select first item [mySegment setSelectedSegmentIndex:0]; //change a segment size [mySegment setWidth:120.0 forSegmentAtIndex:1]; //add a new segment [mySegment insertSegmentWithTitle:@"new" atIndex:2 animated:YES]; //add segment to main view [self.view addSubview:mySegment]; }
以上是关于使用UISegmentedControl从一组或一组值中选择的主要内容,如果未能解决你的问题,请参考以下文章