Reputation: 221
I'm trying to change the color of a UILabel depending on the .text
value it's holding.
I've come up with this but it doesn't seem to work:
titel.text = [NSString stringWithFormat:@"%@", titelJSON];
if (titel.text == @"PROBLEEM") {
titel.textColor = [UIColor redColor];
NSLog(@"1: %@", titel.textColor);
} else if (titel.text == @"WAARSCHUWING") {
titel.textColor = [UIColor orangeColor];
NSLog(@"2: %@", titel.textColor);
} else {
titel.textColor = [UIColor blackColor];
NSLog(@"3: %@", titel.textColor);
}
Any thoughts?
I have logs in there to see what the if
statement is actually picking.
Upvotes: 0
Views: 191
Reputation: 766
You cannot compare strings using == in objective-c. You should use the isEqualToString
message instead. Like [titel.text isEqualToString:@"PROBLEEM"]
Upvotes: 3