码迷,mamicode.com
首页 > 移动开发 > 详细

iOS开篇——UI之UISegmentedControl (分段选择器)

时间:2015-11-24 06:15:20      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:

创建分段选择器

    UISegmentedControl * sc = [[UISegmentedControl alloc]initWithFrame:CGRectMake(50, 100, 200, 30)];
    
    [sc insertSegmentWithTitle:@"第一页" atIndex:0 animated:YES];
    [sc insertSegmentWithTitle:@"第二页" atIndex:1 animated:YES];
    [sc insertSegmentWithTitle:@"第三页" atIndex:2 animated:YES];
    
    [sc addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventValueChanged];

    [self.view addSubview:sc]; 

 

实现点击方法

- (void)onClick:(UISegmentedControl *)sc {
    if (sc.selectedSegmentIndex == 0) {
        [sc removeSegmentAtIndex:0 animated:YES];
    }else if(sc.selectedSegmentIndex == 1){
        [sc insertSegmentWithTitle:@"礼拜" atIndex:0 animated:YES];
    }
}
//根据传来的sc的index值判断执行的方法

 

iOS开篇——UI之UISegmentedControl (分段选择器)

标签:

原文地址:http://www.cnblogs.com/gwkiOS/p/4990251.html

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