How can I convert RGB hex string into UIColor in objective-c?

Posted by dipu on Stack Overflow See other posts from Stack Overflow or by dipu
Published on 2010-06-09T21:47:28Z Indexed on 2010/06/09 21:52 UTC
Read the original article Hit count: 467

Filed under:
|

I have color values coming from the url data is like this, "#ff33cc". How can I convert this value into UIColor? I am attempting with the following lines of code. I am not getting the value for baseColor1 right. Looks like I should take that pound char off. Is there another way to do it?

NSScanner *scanner2 = [NSScanner scannerWithString:@"#ff33cc"];
int baseColor1;
[scanner2 scanHexInt:&baseColor1]; 
CGFloat red = (baseColor1 & 0xFF0000);
[UIColor colorWithRed:red ...

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about rgb