gpt4 book ai didi

ios - UIButton 突出显示设置行为很奇怪

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:22:01 24 4
gpt4 key购买 nike

我突出显示的图像显示不同。这是我的情况。

[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;
}
  1. 触摸按钮。
  2. 按钮显示突出显示的图像。 (正确的图片)
  3. 按钮的状态设置为“选中”
  4. 触摸按钮。
  5. 按钮显示不同的突出显示图像。

当按钮处于选中状态时,突出显示的图像显示不正确。有什么想法吗?

最佳答案

这是因为您同时设置了 setImage:forControllState:UIControlStatesSelected 和 setHighlighted 图像,当您第一次按下按钮时,它的状态被取消选中,显示突出显示的图像,再次按下按钮时,它显示选定的图像,因为现在按钮处于选中状态。 (简而言之,突出显示的图像仅在按钮未选中的状态下有效)。

关于ios - UIButton 突出显示设置行为很奇怪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10706851/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com