iOS开发进阶iOS Developer

iOS UIButton选中状态切换

2017-06-15  本文已影响689人  骑马纵天下
UIButton*payBtn = [UIButtonbuttonWithType:UIButtonTypeCustom];
payBtn.frame=CGRectMake(size.width-24-15,13,24,24);
payBtn.tag= j +1;
[payBtnsetImage:IMG(@"selectNo")forState:UIControlStateNormal];
[payBtnsetImage:IMG(@"selectNo")forState:UIControlStateHighlighted];
[payBtnsetImage:IMG(@"selectYes")forState:UIControlStateSelected];
[payBtnsetImage:IMG(@"selectYes")forState:UIControlStateSelected|UIControlStateHighlighted];
[payBtnaddTarget:selfaction:@selector(selectPayStyle:)forControlEvents:UIControlEventTouchUpInside];
[payStyleLabeladdSubview:payBtn];

- (void)selectPayStyle:(UIButton*)btn{
if(btn !=self.selectedBtn) {
self.selectedBtn.selected=NO;
btn.selected=YES;
self.selectedBtn= btn;
}else{
self.selectedBtn.selected=YES;
}

}```
![](http:https://img.haomeiwen.com/i1483397/5084ec0e3bf6c13c.gif?imageMogr2/auto-orient/strip)
上一篇下一篇

猜你喜欢

热点阅读