title: Convert Hex Color Code to NSColor
body: <p>I am having some trouble converting a a hexcode to an NSColor. Note this is for a Mac App (hence the NSColor instead of UIColor). This is the code I have so far:</p>
  
  <pre><code>- (NSColor *) createNSColorFromString:(NSString *)string {
  NSString* hexNum = [string substringFromIndex:1];
  NSColor* color = nil;
  unsigned int colorCode = 0;
  unsigned char red, green, blue;
  if (string) {
      NSScanner* scanner = [NSScanner scannerWithString:hexNum];
      (void) [scanner scanHexInt:&amp;colorCode];
  }
  red = (unsigned char) (colorCode &gt;&gt; 16);
  green = (unsigned char) (colorCode &gt;&gt; 8);
  blue = (unsigned char) (colorCode);
  color = [NSColor colorWithCalibratedRed:(float)red / 0xff green:(float)green / 0xff blue:(float)blue / 0xff alpha:1.0];
  return color;
  </code></pre>
  
  <p>}</p>
  
  <p>Any help would be appreciated.</p>