[IOS] iphone之UISegmentedControl

代码如下:

//选择按钮
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);
}



posted @ 2011-10-12 09:08  松花江以南  阅读(2853)  评论(0编辑  收藏  举报