UISegmentedControl分段按钮的使用

 

UISegmentedControl分段按钮的使用 | 郝旭.

实现如下代码:

- (void)viewDidLoad {
[super viewDidLoad];
segmentedControl=[[UISegmentedControl alloc] initWithFrame:CGRectMake(80.0f, 8.0f, 70.0f, 25.0f) ];
[segmentedControl insertSegmentWithTitle:@"T+" atIndex:0 animated:YES];
[segmentedControl insertSegmentWithTitle:@"T-" atIndex:1 animated:YES];
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.momentary = YES;
segmentedControl.multipleTouchEnabled=NO;
[segmentedControl addTarget:self action:@selector(Selectbutton:) forControlEvents:UIControlEventValueChanged];
UIBarButtonItem *segButton = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
[segmentedControl release];
self.navigationItem.rightBarButtonItem = segButton;
[segButton release];

}

-(void)Selectbutton:(int)sender{
UISegmentedControl *myUISegmentedControl=(UISegmentedControl *)sender;
NSLog(@”!!!!!!!!%d”,myUISegmentedControl.selectedSegmentIndex);
switch (myUISegmentedControl.selectedSegmentIndex) {
case 1:
break;
case 0:
break;
default:
break;
}
}

http://blog.sealyu.com/2011/01/01/uisegmentedcontrol%E5%88%86%E6%AE%B5%E6%8C%89%E9%92%AE%E7%9A%84%E4%BD%BF%E7%94%A8-%E9%83%9D%E6%97%AD/

你可能感兴趣的:(c,action)