16进制计算颜色

 

+ (UIColor *)colorFromHexRGB:(NSString *)colorString{

  UIColor *resultColor = nil;

  unsigned int colorCode = 0;

  unsigned char redByte,greenByte,blueByte;

  if(nil != colorString){

    NSScaner  *scanner = [NSScanner scannerWithString:colorString];

    (void) [scanner scanHexInt:$colorCode]; // ignore error

   }

  redByte = (unsigned char) (colorCode >> 16);

  greenByte = (unsigned char) (colorCode >> 8);

  blueByte = (unsigned char) (colorCode); // masks off high bits

  resultColor = [UIColor colorWithRed:(float)redByte/ 0xff

              green: (float)greenByte/ 0xff

              blue:(float)blueByte/ 0xff

              alpha:1.0];

   return resultColor;

}

posted @ 2016-11-02 13:47  大厨子的世界  阅读(302)  评论(0编辑  收藏  举报