当点击切换不同状态时:
1.不用Bool值:
_collectBtn setBackgroundImage:[UIImage imageNamed:@"收藏按钮"] forState:UIControlStateNormal];
[_collectBtn setBackgroundImage:[UIImage imageNamed:@"已收藏"] forState:UIControlStateSelected];
点击方法写
sender.selected = !sender.selected;
if (sender.selected) {
}
else{
}
2.使用Bool值:
全局定义一个 Bool isRect;
if (isRect) {
isRect = NO;
[_loginview.rememberButton setImage:[UIImage imageNamed:@"记住密码未选中"] forState:UIControlStateNormal];
}
else{
isRect = YES;
[_loginview.rememberButton setImage:[UIImage imageNamed:@"记住密码"] forState:UIControlStateNormal];
}
网友评论