In an UIWebview, I load a html page whose background color is #CBCDCF. In the previous ViewController (in this ViewController I don't use UIWebview), I want to set the background color to the same value: #CBCDCF. How can I do it?
Asked
Active
Viewed 283 times
-1
-
No. To set color for uiview, I intended to use [self.view setBackgroundColor:anUIColor]; To initialize anUIColor, I see no method to initialize it with a color code such as #CBCDCF. – thomasdao Oct 24 '12 at 10:06
-
It'will be interesting to know if my answer helped you – oiledCode Oct 28 '12 at 18:19
1 Answers
0
You can use a macro like this
#define HEXCOLOR(c) [UIColor colorWithRed:((c>>24)&0xFF)/255.0 \
green:((c>>16)&0xFF)/255.0 \
blue:((c>>8)&0xFF)/255.0 \
alpha:1.0]
and you can do this :
[yourViewController setBackgroundColor:HEXCOLOR(0xCBCDCF)]

oiledCode
- 8,589
- 6
- 43
- 59
-
This macro does not work for me, I've found a right one here: http://stackoverflow.com/questions/1560081/how-can-i-create-a-uicolor-from-a-hex-string – Esteve Jan 05 '15 at 00:26