title: How to convert UIColor to HEX and display in NSLog
body: <p>I have checked several links on how to convert UIColor codes to HEX however I am not sure on how to  call to the method to display them in NSLog. I haven't got the reputation to comment so posting as a question is my last resort. <strong>I want it to display when I run my app in the log.</strong></p>
  
  <p>Second, where do I input the RGB color number ( R = 30, G = 171, B = 13)? I see that all examples use Array [0], [1], [2] which normally refers to index position, so where do I add the color values?</p>
  
  <p>I have this code:</p>
  
  <pre><code>- (NSString *) hexFromUIColor:(UIColor *)color {
  
      if (CGColorGetNumberOfComponents(color.CGColor) &lt; 4) {
          const CGFloat *components = CGColorGetComponents(color.CGColor);
          color = [UIColor colorWithRed:components[30] green:components[141] blue:components[13] alpha:components[1]];
      }
      if (CGColorSpaceGetModel(CGColorGetColorSpace(color.CGColor)) != kCGColorSpaceModelRGB) {
          return [NSString stringWithFormat:@"#FFFFFF"];
      }
      return [NSString stringWithFormat:@"#%02X%02X%02X", (int)((CGColorGetComponents(color.CGColor))[0]*255.0), (int)((CGColorGetComponents(color.CGColor))[1]*255.0), (int)((CGColorGetComponents(color.CGColor))[2]*255.0)];
  
  }
  </code></pre>
  
  <p>Links I have checked:</p>
  
  <p><a href="https://stackoverflow.com/questions/10285365/hex-color-from-uicolor/13134326#13134326">hex color from uicolor</a></p>
  
  <p><a href="https://stackoverflow.com/questions/3805177/how-to-convert-hex-rgb-color-codes-to-uicolor">How to convert HEX RGB color codes to UIColor?</a></p>
  
  <p>I have tried to call the method in viewDidLoad however it wont work without UIColor. I am sure it's something simple. </p>
  
  <p>Thanks to anyone who answers.</p>
  
  <p>What is the code I use in my viewDidLoad to call to this method in order to display in NSLog?</p>