Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to I properly set UIColor from int?

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

Earlier in the program I have

textView.textColor = 0x000000;

but later, when I have

textView.textColor = 0x888888;

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

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

like image 892
Josh Wang Avatar asked Oct 16 '13 13:10

Josh Wang


1 Answers

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];

Then you can use like

textView.textColor = UIColorFromRGB(0x888888);

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

enter image description here

like image 171
Nitin Gohel Avatar answered Sep 28 '22 17:09

Nitin Gohel