如何从int正确设置UIColor? [英] How to I properly set UIColor from int?

查看:389
本文介绍了如何从int正确设置UIColor?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过为其分配值来设置UITextViewtextColor.

I am trying to set the textColor of a UITextView by assigning it a value.

我在程序中的较早版本

textView.textColor = 0x000000;

但是后来,当我有

textView.textColor = 0x888888;

弹出一个致命错误,说:"ARC不允许将'int'隐式转换为'UIColor *'.

a fatal error pops up saying: "Implicit conversion of 'int' to 'UIColor *' is disallowed with ARC".

如何将我的int转换为UIColor以正确设置文本颜色?为什么它不能与0x000000一起使用,而不能与0x888888一起使用?

How do I convert my int to a UIColor to properly set the text color? Why did it work with 0x000000 and not 0x888888?

推荐答案

正如您提交的答案一样,这不是答案.UIColorFromRGB是上面在@implementation处定义的宏,例如

as par you submited answer this is not an answer UIColorFromRGB is a Macro that define above at @implementation like

#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0];

然后您可以像

textView.textColor = UIColorFromRGB(0x888888);

您可以使用其UIColor属性在目标c中设置文本bg-color等的颜色

you can use its property of UIColor for setting color of text bg-color etc in objective c

这篇关于如何从int正确设置UIColor?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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