标签:
UISwitch *myswitch=[[UISwitch alloc]initWithFrame:CGRectMake(100, 40, 0, 0)];
//打开时颜色
myswitch.onTintColor=[UIColor redColor];
//关闭时颜色
myswitch.tintColor=[UIColor blueColor];
//打开关闭图片
myswitch.onImage=[UIImage imageNamed:@"1"];
myswitch.offImage=[UIImage imageNamed:@"2"];
//设置初始状态
myswitch.on=YES;
[myswitch setOn:YES animated:YES];
//添加点击事件
[myswitch addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:myswitch];
标签:
原文地址:http://www.cnblogs.com/kyuubee/p/4804828.html