gpt4 book ai didi

ios - 在 IOS 中单击时更改按钮文本颜色

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

我知道这个问题经常被问到,而且很多答案都是正确的,我的代码中遇到了问题。我有单选按钮,当用户单击按钮时,背景颜色和文本颜色会发生变化。背景颜色如我所料更改,但单击按钮时文本颜色变为蓝色区域。我已将其编码为单击时更改白色,但是当我单击按钮时它将文本区域更改为蓝色,我很困惑我在哪里做错了。我的代码是,

 self.selectedTitleColor = [UIColor whiteColor];
self.selectedBackgroundColor = [UIColor redColor];

self.unselectedTitleColor = [UIColor blackColor];
self.unselectedBackgroundColor = [UIColor whiteColor];

- (IBAction)House:(id)sender {

[sender setSelected: ![sender isSelected]];
[self.flat setSelected:NO];
[self.lowerP setSelected:NO];
[self.upperP setSelected:NO];
[self.farmH setSelected:NO];
[self.pentH setSelected:NO];
[self.roomB setSelected:NO];


[self updateButtonColors];

-(void)updateButtonColors {
if (self.house.selected) {
[self.house setTitleColor:self.selectedTitleColor forState:UIControlStateNormal];
[self.house setBackgroundColor:self.selectedBackgroundColor];

House=_house.titleLabel.text;
ImageViewD = [NSString stringWithFormat:@"%@",House];

NSLog(@"HHHH %@",ImageViewD);

} else {
[self.house setTitleColor:self.unselectedTitleColor forState:UIControlStateNormal];
[self.house setBackgroundColor:self.unselectedBackgroundColor];
}

enter image description here

最佳答案

将 Storyboard 中的按钮类型从系统更改为自定义

enter image description here

关于ios - 在 IOS 中单击时更改按钮文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45210659/

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