无法更改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];
标签文字颜色是白色的,而不是我的自定义颜色。
感谢任何帮助。
UIColor的RGB组件的缩放比例介于0和1之间,而不是255。
尝试
categoryTitle.textColor = [UIColor colorWithRed:(188/255.f) green:... blue:... alpha:1.0];
在Swift中:
categoryTitle.textColor = UIColor(red: 188/255.0, green: ..., blue: ..., alpha: 1)
可能更好的方法是
UIColor *color = [UIColor greenColor];
[self.myLabel setTextColor:color];
因此我们有彩色文字
试试这个,其中阿尔法是不透明的,其他是红色,绿色,蓝色chanels-
self.statusTextLabel.textColor = [UIColor colorWithRed:(233/255.f) green:(138/255.f) blue:(36/255.f) alpha:1];
链接地址: http://www.djcxy.com/p/28237.html