我知道这个问题经常被问到,而且很多答案都是正确的,我的代码中我遇到了一个问题。我有单选按钮,当用户单击按钮背景颜色和文本颜色更改时。背景颜色按照我的预期更改,但单击按钮时文本颜色变为蓝色区域。我已将其编码为单击时更改白色但当我单击按钮时将文本区域更改为蓝色,我很困惑我在哪里犯错误。我的代码是,
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];
}
}