无法更改 UILabel 文本颜色
我想更改 UILabel 文本颜色,但无法更改颜色,这就是我的代码的样子。
UILabel *categoryTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 46, 16)];
categoryTitle.text = @"abc";
categoryTitle.backgroundColor = [UIColor clearColor];
categoryTitle.font = [UIFont systemFontOfSize:12];
categoryTitle.textAlignment = UITextAlignmentCenter;
categoryTitle.adjustsFontSizeToFitWidth = YES;
categoryTitle.textColor = [UIColor colorWithRed:188 green:149 blue:88 alpha:1.0];
[self.view addSubview:categoryTitle];
[categoryTitle release];
标签文本颜色是白色,不是我的自定义颜色。
感谢您的帮助。
I want to change the UILabel text color but I can't change the color, This is how my code looks like.
UILabel *categoryTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 46, 16)];
categoryTitle.text = @"abc";
categoryTitle.backgroundColor = [UIColor clearColor];
categoryTitle.font = [UIFont systemFontOfSize:12];
categoryTitle.textAlignment = UITextAlignmentCenter;
categoryTitle.adjustsFontSizeToFitWidth = YES;
categoryTitle.textColor = [UIColor colorWithRed:188 green:149 blue:88 alpha:1.0];
[self.view addSubview:categoryTitle];
[categoryTitle release];
The label text color is white ,not my custom color.
Thank for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
UIColor 的 RGB 分量在 0 到 1 之间缩放,最大不超过 255。
尝试
在 Swift 中:
UIColor's RGB components are scaled between 0 and 1, not up to 255.
Try
In Swift:
可能更好的方法是
因此我们有彩色文本
May be the better way is
Thus we have colored text
试试这个,其中 alpha 是不透明度,其他是红色、绿色、蓝色通道 -
Try this one, where alpha is opacity and others is Red,Green,Blue chanels-
有可能,它们在 InterfaceBuilder 中没有连接。
文本颜色
(colorWithRed:(188/255) green:(149/255) blue:(88/255))
正确,可能连接错误,backgroundcolor用于标签背景色textcolor 用于属性 textcolor。
It is possible, they are not connected in InterfaceBuilder.
Text colour
(colorWithRed:(188/255) green:(149/255) blue:(88/255))
is correct, may be mistake in connections,backgroundcolor is used for the background colour of label and textcolor is used for property textcolor.
在 swift 代码中添加属性文本颜色。
斯威夫特 4:
对于斯威夫特 3:
Add attributed text color in swift code.
Swift 4:
for Swift 3:
colorWithRed:green:blue:alpha:文档链接
colorWithRed:green:blue:alpha: documentation link