将16进制的颜色值变成UIColor

+ ( UIColor *) colorFromHexRGB :( NSString *) inColorString
{
  UIColor *result = nil ;
  unsigned int colorCode = 0 ;
  unsigned char redByte, greenByte, blueByte;
  
  if (nil != inColorString)
  {
   NSScanner *scanner = [ NSScanner scannerWithString :inColorString];
   ( void ) [scanner scanHexInt :&colorCode;]; // ignore error
  }
  redByte = (unsigned char ) (colorCode >> 1 6 );
  greenByte = (unsigned char ) (colorCode >> 8 );
  blueByte = (unsigned char ) (colorCode); // masks off high bits
  result = [UIColor
            colorWithRed : ( float )redByte / 0 xff
            green : ( float )greenByte/ 0 xff
            blue : ( float )blueByte / 0 xff
            alpha : 1 .0 ];   
  return result;
}

你可能感兴趣的:(将16进制的颜色值变成UIColor)