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

UISegmentedControl的常用属性和用法

时间:2016-02-05 22:23:35      阅读:324      评论:0      收藏:0      [点我收藏+]

标签:

1.UISegmentControl

1)先创建一个数组用来存放标题

NSArray *array = @[@"1",@"2",@"3",nil];

UISegmentedControl *segmented = [[UISegmentedControl alloc] initWithItems:array];

[segmented insertSegmentWithTitle:@"3" atIndex:3 animated:NO];

[segmented removeSegmentAtIndex:3 animated:NO];

[segmented setImage:[UIImage ImageNamed:@"2.png"] forSegmentAtIndesx:1];

[segmented setTitle:@"分组1" forSegmentAtIndex:0];

[segmented setWidth:60 fotSegmentAtIndex:0];

//UISegmented的点击事件,后面的控制事件的状态一定是valueChanged

[segmented addTarget:self action:@selector(segmentAction:) forControlEvent:UIControlEventValueChanged];

2.通常UISegmentedControl的点击事件和switch case结合使用

- (void)segmentedAction:(UISegmentedControl *)segmented {

  switch (segmented.selectedSegmentIndex) {

  case 0 :

self.backGroundColor = [UIColor yellowColor];

  break;

  default:

  break;

}

}

 

UISegmentedControl的常用属性和用法

标签:

原文地址:http://www.cnblogs.com/arenouba/p/5183622.html

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