Posted By

espinallab on 02/24/10


Tagged

UIColor UIColorFromRGB


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

umang_nine
cdnicoll
cnathan


Transform hex color to objective-c color.


 / Published in: Objective C
 

URL: http://www.reigndesign.com/blog/liven-up-your-boring-uitableview-part-1/

This is exactly what I was looking for since I come from web development

  1. //If you come from a web development background, you're probably more used to hex color //strings. Put this macro at the top of your .m file, after the imports
  2.  
  3. #define UIColorFromRGB(rgbValue) [UIColor \
  4. colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
  5. green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
  6. blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
  7.  
  8. //Now you can simply write
  9. cell.textColor = UIColorFromRGB(0xFF3366);

Report this snippet  

You need to login to post a comment.