UIswitch相关代码如下:
- (void)creatUIswitch{
UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectMake(54.0f, 16.0f, 100.0f, 28.0f)];
switchView.on = YES; //设置初始为ON
[switchView addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
}
//当值发生改变是调用
- (void)switchAction:(UISwitch *)sender {
if (sender.on) {
NSLog(@"开!");
}
else
NSLog(@"关!");
}
下面是关于自定义UISwitch的链接。
http://blog.csdn.net/arthurchenjs/article/details/6263591