UIColor from Hex & Photoshop Values


/ Published in: Objective C
Save to your folder(s)



Copy this code and paste it in your HTML
  1. //In header
  2. #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]
  3.  
  4. //usage
  5. UIColor *color = UIColorFromRGB(0x000000)
  6.  
  7. //you can also use it inline
  8. [text.textField setTextColor:UIColorFromRGB(0xcccccc)];
  9.  
  10. #define PhotoshopColorValue(x) (x / 255.0)
  11.  
  12. #define UIColorFromPhotoshopRGBA(r,g,b,a) [UIColor colorWithRed:PhotoshopColorValue(r) green:PhotoshopColorValue(g) blue:PhotoshopColorValue(b) alpha:a]
  13.  
  14. #define UIColorFromPhotoshopHSBA(h,s,b,a) [UIColor colorWithHue:PhotoshopColorValue(h) saturation:PhotoshopColorValue(s) brightness:PhotoshopColorValue(b) alpha:a]
  15.  
  16. #define UIColorFromHexValue(hex) UIColorFromPhotoshopRGBA(((hex & 0xFF0000) >> 16), ((hex & 0xFF00) >> 8), (hex & 0xFF), 1.0)

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.