Objective--C UISegmentedControl 交通灯
2015-12-17 19:20
399 查看
只是简单的点击变化背景颜色,主要记录UISegmentedControl的使用
在viewDidLoad方法下
NSArray *segArr = [[NSArray
alloc] initWithObjects:@"red",@"yellow",@"green",
nil];
UISegmentedControl *seg = [[UISegmentedControl
alloc]
initWithItems:segArr];
seg.frame =
CGRectMake(100,
100, 200, 50);
seg.backgroundColor = [UIColor
cyanColor];
[seg addTarget:self
action:@selector(click:)
forControlEvents:UIControlEventValueChanged];
[self.view
addSubview:seg];
[seg release];
显示的是
,可以进行点击
// 点击事件的实现
- (void)click:(UISegmentedControl *)seg{
NSInteger i = seg.selectedSegmentIndex;
switch (i) {
case
0:
self.view.backgroundColor = [UIColor
redColor];
break;
case
1:
self.view.backgroundColor = [UIColor
yellowColor];
break;
case
2:
self.view.backgroundColor = [UIColor
greenColor];
break;
default:
break;
}
}
在viewDidLoad方法下
NSArray *segArr = [[NSArray
alloc] initWithObjects:@"red",@"yellow",@"green",
nil];
UISegmentedControl *seg = [[UISegmentedControl
alloc]
initWithItems:segArr];
seg.frame =
CGRectMake(100,
100, 200, 50);
seg.backgroundColor = [UIColor
cyanColor];
[seg addTarget:self
action:@selector(click:)
forControlEvents:UIControlEventValueChanged];
[self.view
addSubview:seg];
[seg release];
显示的是
,可以进行点击
// 点击事件的实现
- (void)click:(UISegmentedControl *)seg{
NSInteger i = seg.selectedSegmentIndex;
switch (i) {
case
0:
self.view.backgroundColor = [UIColor
redColor];
break;
case
1:
self.view.backgroundColor = [UIColor
yellowColor];
break;
case
2:
self.view.backgroundColor = [UIColor
greenColor];
break;
default:
break;
}
}
相关文章推荐
- Object-c学习笔记
- Objective--C Slider实现三原色之间颜色变化
- Objective--C UIControl 简易本地音频播放器
- Java基础--面向对象(多态、Object类)
- 翻译:采用现代Objective-C
- Objective--C UI手势
- Responder object
- Objective-c语言_NSDate(时间类型)和NSCalendar(日历)和NSTimeZone(时区)
- Objective-c语言_NSData(不可变数据)和NSMutableData(可变数据)
- 十分钟让你明白Objective-C的语法(和Java、C++的对比)
- Objective-C Block的实现
- Lock object
- Object-C 类,对象,运行时,isa
- Objective-C的单例模式如何新建和测试?
- JSONObject使用方法详解
- 必须了解的Object知识
- Objective-C 中singleton(单例模式)的实现
- Object-C里的类目,延展,协议
- Playing with __attributes__ (一)
- Objective-C中@property的所有属性详解