How can I change the text color of a UITableViewCell in this state?

- (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state if (selected) { companyLabel.textColor = [UIColor whiteColor]; priceLabel.textColor = [UIColor whiteColor]; changeLabel.textColor = [UIColor whiteColor]; symbolLabel.textColor = [UIColor whiteColor]; } else { companyLabel.textColor = [UIColor blackColor]; priceLabel.textColor = [UIColor blackColor]; symbolLabel.textColor = [UIColor blackColor]; if([changeLabel.text doubleValue] < 0) { changeLabel.textColor = [UIColor colorWithRed:239.0/255.0 green:16.0/255.0 blue:52.0/255.0 alpha:1.0]; } else if([changeLabel.text doubleValue] > 0) { changeLabel.textColor = [UIColor colorWithRed:77.0/255.0 green:161.0/255.0 blue:0.0 alpha:1.0]; } } } 

My text will not turn white until AFTER the next view I clicked on the navigation stack.

I want it to turn white even when the user clicked + holds the cell.

+4
source share
4 answers

UILabel have a highlightedTextColor property. When a view like UITableViewCell goes into its selected state, all subzones, including the label, should be automatically changed to use their selected properties. If it still does not work, there is a field to disable this feature that you want to check.

+17
source

You do not want to do this in any tableview delegate methods. You must set the highlighted text color to UILabel as indicated

 [myLabel setHighlightedTextColor:[UIColor whiteColor]]; 

It will work. You also do not want to handle even an unlit state.

Greetings!

+1
source

I would use UITableViewDelegate methods to achieve this. UILabel can set colors, so why not do something using didSelectRowAtIndex and didDeselectRowAtIndex. In the didSelectRowAtIndex file, set the label of the desired color, and then in didDeselectRowAtIndex set the label to black.

0
source

Can you replace the shortcut with UIButton and act on the touchDown event?

The button still has a titleLabel property so that it can display the text in order and you can act more easily. However, I don’t see much of your code, so I don’t know what you are doing with these labels.

-1
source

Source: https://habr.com/ru/post/1369062/


All Articles