Created
March 21, 2013 09:03
-
-
Save helloworld116/5211691 to your computer and use it in GitHub Desktop.
ios:UISegmentedControl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //创建一个UISegmentedControl实例 | |
| NSArray *segmentTextContent = [NSArray arrayWithObjects:@"资讯",@"博客",@"推荐阅读",nil]; | |
| UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:segmentTextContent]; | |
| segment.selectedSegmentIndex = 0; | |
| segment.autoresizingMask = UIViewAutoresizingFlexibleWidth; | |
| segment.segmentedControlStyle = UISegmentedControlStyleBar; | |
| //UISegmentedControl实例添加事件 | |
| [segment addTarget:self action:@selector(segmentedControlChangedValue:) forControlEvents:UIControlEventValueChanged]; | |
| //UISegmentedControl实例对应的事件实现 | |
| -(void) segmentedControlChangedValue:(id)sender{ | |
| int selectIndex = [sender selectedSegmentIndex];//获取segment选中的index,从0开始计数 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment