UIButton*selectBtn = [[UIButton alloc]init];
[selectBtn setImage:[UIImage imageNamed:@"noSelect"] forState:UIControlStateNormal];
[selectBtn addTarget:self action:@selector(selectBtn:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:selectBtn];
[selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.mas_equalTo(10);
make.width.height.mas_equalTo(30);
}];
- (void)selectBtn:(UIButton *)sender{
sender.selected = !sender.selected;
UIButton *btn = (UIButton *)sender;
if(sender.selected) {
[btn setImage:[UIImage imageNamed:@"selectImg"] forState:UIControlStateNormal];
}else{
[btn setImage:[UIImage imageNamed:@"noSelect"] forState:UIControlStateNormal];
}
}
iOS 按钮选中状态
最新推荐文章于 2024-04-23 16:17:15 发布