Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (void)viewDidLoad {
  2.     [super viewDidLoad];
  3.    
  4.     UIColor *cBlue = [UIColor blueColor];
  5.     UIColor *cOrange = [UIColor orangeColor];
  6.     UIColor *cRed = [UIColor redColor];
  7.    
  8.     [self listColorComponents:cBlue   forMyName:@"Blue"];
  9.     [self listColorComponents:cOrange forMyName:@"Orange"];
  10.     [self listColorComponents:cRed    forMyName:@"Red"];
  11.    
  12. }
  13.  
  14. - (void) listColorComponents:(UIColor *)theColor forMyName:(NSString *)theName {
  15.  
  16.     const CGFloat *cColors = CGColorGetComponents(theColor.CGColor);
  17.  
  18.     CGFloat r = cColors[0];
  19.     CGFloat g = cColors[1];
  20.     CGFloat b = cColors[2];
  21.     CGFloat a = cColors[3];
  22.  
  23.     NSLog(@"%@ Red   is %f / %d", theName, r, (int)(r * 255));
  24.     NSLog(@"%@ Blue  is %f / %d", theName, g, (int)(g * 255));
  25.     NSLog(@"%@ Green is %f / %d", theName, b, (int)(b * 255));
  26.     NSLog(@"%@ Alpha is %f / %d", theName, a, (int)(a * 255));
  27.    
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement