UISwitch
2015-08-03 21:20
393 查看
UISwitch *mySwitch = [[UISwitch
alloc] initWithFrame:CGRectMake(100,
100, 100,
100)];
//设置开启颜色
图片
mySwitch.onTintColor = [UIColor
redColor];
mySwitch.onImage = [UIImage
imageNamed:@""];
//设置关闭颜色
图片
mySwitch.tintColor = [UIColor
blueColor];
mySwitch.offImage = [UIImage
imageNamed:@""];
//设置圆形按钮颜色
mySwitch.thumbTintColor = [UIColor
orangeColor];
//代码设置开启/关闭状态
//设置YES或NO,是否使用animated动画效果:
[mySwitch
setOn:YES
animated:YES];
[self.view
addSubview:mySwitch];
[mySwitch addTarget:self
action:@selector(click:)
forControlEvents:UIControlEventValueChanged];
}
- (void)click:(id)sender{
UISwitch *mySwitch = (UISwitch *)sender;
if (mySwitch.isOn) {
NSLog(@"开关开启");
}else{
NSLog(@"开关关闭");
}
}
- (void)didReceiveMemoryWarning {
[super
didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
alloc] initWithFrame:CGRectMake(100,
100, 100,
100)];
//设置开启颜色
图片
mySwitch.onTintColor = [UIColor
redColor];
mySwitch.onImage = [UIImage
imageNamed:@""];
//设置关闭颜色
图片
mySwitch.tintColor = [UIColor
blueColor];
mySwitch.offImage = [UIImage
imageNamed:@""];
//设置圆形按钮颜色
mySwitch.thumbTintColor = [UIColor
orangeColor];
//代码设置开启/关闭状态
//设置YES或NO,是否使用animated动画效果:
[mySwitch
setOn:YES
animated:YES];
[self.view
addSubview:mySwitch];
[mySwitch addTarget:self
action:@selector(click:)
forControlEvents:UIControlEventValueChanged];
}
- (void)click:(id)sender{
UISwitch *mySwitch = (UISwitch *)sender;
if (mySwitch.isOn) {
NSLog(@"开关开启");
}else{
NSLog(@"开关关闭");
}
}
- (void)didReceiveMemoryWarning {
[super
didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
相关文章推荐
- [2015hdu多校联赛补题]hdu5297 Y sequence
- hdoj 1005 Number Sequence
- zoj2587 Unique Attack 判断最小割是否唯一
- Havok_2014-1-0_Pc_Xs_User_Guide(1.1.1-简介)
- 怎么解决UIScrollView把uitableviewcell的点击事件屏蔽了
- UISwitch
- STL之queue
- HDOJ 1509 Windows Message Queue(优先队列)
- easyui动态添加下拉框选项
- UIViewController与TextField的位置调整
- MFC:ON_UPDATE_COMMAND_UI和ON_COMMAND消息的区别
- UIKit 选项卡栏控制器 UITabBarController (未完成)
- MFC:CCmdUI类的功能
- HDU 1509:Windows Message Queue【优先队列】
- iOS UI04_Touch
- hdu 5329 Question for the Leader
- XML::Parser perl module is required for intltool错误
- Uva 11324 The Largest Clique【强连通 DAG动规 spfa】
- UVa 10534 DP LIS Wavio Sequence
- wpf鼠标捕获与控件交互——UIElement.CaptureMouse