我突出显示的图像显示不同。 这是我的情况。
[button setImage:"normal image" forState:UIControlStateNormal];
[button setImage:"hover image" forState:UIControlStateHighlighted];
[button setImage:"hover image" forState:UIControlStateSelected];
- (IBAction)buttonTouched:(id)sender {
UIButton *selectButton = sender;
if (_currentSelectedTabButton.tag == selectButton.tag) {
//TODO refresh view controller
return ;
}
_currentSelectedTabButton.selected = NO;
selectButton.selected = YES;
_currentSelectedTabButton = selectButton;
}
- 触摸按钮。
- 按钮显示突出显示的图像。 (正确图片)
- 按钮的状态设置为“已选择”
- 触摸按钮。
- 按钮显示不同的突出显示图像。
当按钮处于选定状态时,突出显示的图像显示不正确。 有什么想法吗?
最佳答案
这是因为您同时设置了 setImage:forControllState:UIControlStatesSelected 和 setHighlighted 图像,并且当您第一次按下按钮时,其状态未被选择,突出显示的图像会显示,再次按下按钮时,它会显示选定的图像,因为现在按钮处于选中状态。 (总之,突出显示的图像仅在按钮的非选定状态下起作用)。
关于ios - UIButton 突出显示设置行为很奇怪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10706851/