priore

UIColor from hex

May 21st, 2012
840
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. + (UIColor* ) colorWithHex:(int)color {
  2.  
  3.     float red = (color & 0xff000000) >> 24;
  4.     float green = (color & 0x00ff0000) >> 16;
  5.     float blue = (color & 0x0000ff00) >> 8;
  6.     float alpha = (color & 0x000000ff);
  7.  
  8.     return [UIColor colorWithRed:red/255.0 green:green/255.0 blue:blue/255.0 alpha:alpha/255.0];
  9. }
  10.  
  11. + (UIColor *) colorWithHexRed:(int)red green:(char)green blue:(char)blue alpha:(char)alpha {
  12.     int x = 0;
  13.     x |= (red & 0xff) << 24;
  14.     x |= (green & 0xff) << 16;
  15.     x |= (blue & 0xff) << 8;
  16.     x |= (alpha & 0xff);
  17.     return [UIColor colorWithHex:x];
  18. }
  19.  
  20. // UIColor *redColor = [UIColor colorWithHex:0xff0000ff];
Advertisement
Add Comment
Please, Sign In to add comment