原文地址:[url]http://blog.sina.com.cn/s/blog_4adf31ea0100tsd3.html[/url] 作者:飞舞的鸡毛
[img]http://s12.sinaimg.cn/middle/4adf31eat76b2e24823fb&690[/img]
代码:
//选择按钮
NSArray *buttonNames = [NSArray arrayWithObjects:@"今天", @"本周", @"本月", nil];
UISegmentedControl* segmentedControl = [[UISegmentedControl alloc] initWithItems:buttonNames];
[segmentedControl setFrame:CGRectMake(60, 10, 200, 40)];
segmentedControl.selectedSegmentIndex=1;
//添加事件
[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:segmentedControl];
[segmentedControl release];
//事件
-(void)segmentAction:(UISegmentedControl *)Seg{
NSInteger Index = Seg.selectedSegmentIndex;
NSLog(@"Seg.selectedSegmentIndex:%d",Index);
}
[img]http://s12.sinaimg.cn/middle/4adf31eat76b2e24823fb&690[/img]
代码:
//选择按钮
NSArray *buttonNames = [NSArray arrayWithObjects:@"今天", @"本周", @"本月", nil];
UISegmentedControl* segmentedControl = [[UISegmentedControl alloc] initWithItems:buttonNames];
[segmentedControl setFrame:CGRectMake(60, 10, 200, 40)];
segmentedControl.selectedSegmentIndex=1;
//添加事件
[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:segmentedControl];
[segmentedControl release];
//事件
-(void)segmentAction:(UISegmentedControl *)Seg{
NSInteger Index = Seg.selectedSegmentIndex;
NSLog(@"Seg.selectedSegmentIndex:%d",Index);
}