码迷,mamicode.com
首页 > 其他好文 > 详细

UI控件(UISegmentedControl)

时间:2016-02-11 10:04:46      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSArray* segmentArray = [[NSArray alloc]initWithObjects:@"Title1", @"Title2", @"Title3",nil];
    
    //也可以通过insertSegmentWithtitile方法添加选项
    //也可以对某个选项选择添加图片
    UISegmentedControl* segmentedControl = [[UISegmentedControl alloc]initWithItems:segmentArray];
    segmentedControl.frame = CGRectMake(30, 20, 250, 30);
    
    //设置选项卡的默认点击项,从索引0开始
    segmentedControl.selectedSegmentIndex = 0;
    
    //分段选项卡的颜色,默认为蓝色
    segmentedControl.tintColor = [UIColor redColor];
    
    //设置选项卡在点击后是否会恢复原状
    segmentedControl.momentary = NO;
    
    //segmentedControlStyle 在IOS 7以后无效
    //segmentedControl.segmentedControlStyle = UISegmentedControlStyleBezeled;
    
    //添加选项卡选择事件
    [segmentedControl addTarget:self action:@selector(doSelected:) forControlEvents:UIControlEventValueChanged];
    
    [self.view addSubview:segmentedControl];
    
}

-(void)doSelected:(id)sender{
    UISegmentedControl* tmp = (UISegmentedControl*)sender;
    NSLog(@"%ld", tmp.selectedSegmentIndex);
}

@end

 

UI控件(UISegmentedControl)

标签:

原文地址:http://www.cnblogs.com/Fredric-2013/p/5186310.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!