ios 更改 UILabel 的文本颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6951482/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
changing the text color of a UILabel
提问by banditKing
Hi Im trying to change the text color of a UILabel in one of my views but having no luck.
嗨,我试图在我的一个视图中更改 UILabel 的文本颜色,但没有运气。
Is there something quite obvious that Im not doing in this code?
我在这段代码中没有做一些很明显的事情吗?
self.nameTopRight.backgroundColor = [UIColor redColor];
self.nameBottomRight.textColor = [UIColor redColor];
采纳答案by cdasher
They need to be connected in Interface Builder.
它们需要在 Interface Builder 中连接。
回答by Suragch
The question was already answered for the OP, but for the sake of other people who come here trying to change a label's text color, use the textColor
property:
OP 已经回答了这个问题,但是为了其他试图更改标签文本颜色的人,请使用以下textColor
属性:
Swift
迅速
myLabel.textColor = UIColor.red
Objective-C
目标-C
myLabel.textColor = [UIColor redColor];
回答by Gulshan Kumar
You can also set the UIColor via RGB values like so:
您还可以通过 RGB 值设置 UIColor,如下所示:
myLabel.textColor= [UIColor colorWithRed:(160/255.0) green:(97/255.0) blue:(5/255.0) alpha:1];
回答by ashokdy
Text color is the correct one, may be mistake in connections,
文字颜色是正确的,可能是连接错误,
backgroundcolor is used for the label background color and for the textcolor use property textcolor
backgroundcolor 用于标签背景颜色和 textcolor 使用属性 textcolor