简体   繁体   English

Xcode UITableView更改以编程方式创建的高亮显示的单元格文本颜色

[英]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: 通过使用正确的坐标创建标签,然后键入以下内容,我向UITableViewCell添加了一些文本:

[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. 我在标签“重复”和重叠上遇到了问题,但我通过将代码放在if (cell == nil)函数中来解决了这个问题。 Now my question is: When you select the cell it highlights in blue. 现在我的问题是:当您选择单元格时,它会以蓝色突出显示。 With the default cell.textLabel.text it goes white when highlighted. 使用默认的cell.textLabel.text时,突出显示时为白色。 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. 使用默认的cell.textLabel.text时,突出显示时为白色。 This does not happen on my custom labels. 这在我的自定义标签上不会发生。 Could someone explain how to do this please? 有人可以解释怎么做吗?

UILabel has a property named highlightedTextColor . UILabel有一个名为属性highlightedTextColor You need to set this property: 您需要设置此属性:

labelDesc.highlightedTextColor = [UIColor whiteColor];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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