无法更改UILabel文本颜色 [英] Can not change UILabel text color

查看:102
本文介绍了无法更改UILabel文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改UILabel文本的颜色,但不能更改颜色,这就是我的代码的样子.

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.

感谢您的帮助.

推荐答案

UIColor的RGB分量在0到1之间缩放,最大不超过255.

UIColor's RGB components are scaled between 0 and 1, not up to 255.

尝试

categoryTitle.textColor = [UIColor colorWithRed:(188/255.f) green:... blue:... alpha:1.0];


在Swift中:


In Swift:

categoryTitle.textColor = UIColor(red: 188/255.0, green: ..., blue: ..., alpha: 1)

这篇关于无法更改UILabel文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆