更改 UILabel 的文本颜色

Posted

技术标签:

【中文标题】更改 UILabel 的文本颜色【英文标题】:changing the text color of a UILabel 【发布时间】:2011-08-05 04:33:29 【问题描述】:

您好,我试图在我的一个视图中,但没有运气。

我在这段代码中没有做一些很明显的事情吗?

self.nameTopRight.backgroundColor = [UIColor redColor];
self.nameBottomRight.textColor = [UIColor redColor];

【问题讨论】:

【参考方案1】:

OP 已经回答了这个问题,但是为了其他人来这里尝试更改标签的文本颜色,请使用 textColor 属性:

斯威夫特

myLabel.textColor = UIColor.red  // or .red

目标-C

myLabel.textColor = [UIColor redColor];

【讨论】:

【参考方案2】:

它们需要在 Interface Builder 中连接。

【讨论】:

【参考方案3】:

您还可以通过 RGB 值设置 UIColor,如下所示:

myLabel.textColor= [UIColor colorWithRed:(160/255.0) green:(97/255.0) blue:(5/255.0) alpha:1];

【讨论】:

【参考方案4】:

文字颜色是正确的,可能是连接错误,

backgroundcolor 用于标签背景颜色,textcolor 使用属性 textcolor

【讨论】:

以上是关于更改 UILabel 的文本颜色的主要内容,如果未能解决你的问题,请参考以下文章

更改 UItableViewCell 中的 UILabel 文本颜色

从 UITableViewCell 中点击 Swift 更改标签文本颜色

当我在 ios 中展开和折叠 TableList 单元格时如何更改 UILabel 文本颜色

UIProgressBar:如何根据背景颜色更改 UILabel 颜色

UITableView,UILabel 文本颜色在选择行时没有改变? [关闭]

更改数组中 UILabel 的背景颜色