gpt4 book ai didi

ios - UIButton:单击时更改标题颜色,单击其他按钮时更改回来

转载 作者:行者123 更新时间:2023-11-29 02:51:25 24 4
gpt4 key购买 nike

我希望 aButton 在我单击时将 titleColor 从白色更改为红色

但是当我点击其他按钮时,我希望 aButton 变回白色

我该怎么做?

这是我写的代码,但它不能按我想要的方式运行。

[aButton setTitleColor:[UIColor redColor] forState:UIControlStateSelected];

最佳答案

使用setSelected:改变按钮的选择状态。

在viewDidLoad中:

[aButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[aButton setTitleColor:[UIColor redColor] forState:UIControlStateSelected];

[bButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[bButton setTitleColor:[UIColor redColor] forState:UIControlStateSelected];

aButton.selected = YES;


- (IBAction)aButton_or_bButtonClicked:(id)sender {

if(aButton.selected) {
aButton.selected = NO;
bButton.selected = YES;
}
else {
aButton.selected = YES;
bButton.selected = NO;
}
}

关于ios - UIButton:单击时更改标题颜色,单击其他按钮时更改回来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24476208/

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