Skip to content

Instantly share code, notes, and snippets.

@helloworld116
Created March 21, 2013 09:03
Show Gist options
  • Save helloworld116/5211691 to your computer and use it in GitHub Desktop.
Save helloworld116/5211691 to your computer and use it in GitHub Desktop.
ios:UISegmentedControl
//创建一个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