我想更改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];
标签文本颜色为白色,而不是我的自定义颜色 .
感谢您的帮助 .
6 回答
UIColor的RGB分量在0和1之间缩放,而不是255 .
尝试
在Swift中:
可能是更好的方法
因此我们有彩色文字
试试这个,其中alpha是不透明的,其他是红色,绿色,蓝色chanels-
它们可能在InterfaceBuilder中没有连接 .
文字颜色
(colorWithRed:(188/255) green:(149/255) blue:(88/255))
是正确的,可能是连接错误,backgroundcolor用于标签的背景颜色,textcolor用于属性textcolor .
在swift代码中添加属性文本颜色 .
斯威夫特4:
对于Swift 3:
colorWithRed:green:blue:alpha: documentation link