Change Button Text Color When Clicked in IOS

Viewed 1253

I know this question is asked frequently and many of answers are correct, I have my code in which I'm facing an issue. I have radio buttons on which when user click the button background color and text color changes. The background color is changed as I expected but the text color turns blue area when the button is clicked. I have coded it to change white color when click but when I click the button it changes the text area to blue, I'm confused that where I'm doing mistakes. My code is,

 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

2 Answers
Related