简体   繁体   中英

Xcode UITableView change programmatically created cell text color on highlight

I have added some text to a UITableViewCell by creating the label with the correct coords, then typing the following:

[cell.contentView addSubview:labelDesc];

All is well. I had an issue with the labels "duplicating" and overlapping, but I fixed it by putting the code in the if (cell == nil) function. Now my question is: When you select the cell it highlights in blue. With the default cell.textLabel.text it goes white when highlighted. This does not happen on my custom labels.

When you select the cell it highlights in blue. With the default cell.textLabel.text it goes white when highlighted. This does not happen on my custom labels. Could someone explain how to do this please?

UILabel has a property named highlightedTextColor . You need to set this property:

labelDesc.highlightedTextColor = [UIColor whiteColor];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM