您的位置:首页 > 产品设计 > UI/UE

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.
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: