我正在尝试使用以下代码使 UI Button 成为切换按钮:
- (void)tapButton:(id)sender{
UIButton *button = sender;
if (!button.selected){
[self performSelector:@selector(highlight:) withObject:button afterDelay:0.0];
}else{
[self performSelector:@selector(removeHighlight:) withObject:button afterDelay:0.0];
}
}
- (void)highlight:(UIButton *)button{
button.selected = !button.selected;
button.highlighted = YES;
}
- (void)removeHighlight:(UIButton *)button{
button.selected = !button.selected;
button.highlighted = NO;
}
但是,当按钮处于选定模式时,我得到了一个奇怪的伪像。
未选中的:
已选择: