美文网首页
 对十六进制颜色的设置

 对十六进制颜色的设置

作者: Kloar | 来源:发表于2016-02-20 16:45 被阅读25次

    - (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 >> 16);

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

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

    result = [UIColor

    colorWithRed: (float)redByte / 0xff

    green: (float)greenByte/ 0xff

    blue: (float)blueByte / 0xff

    alpha:1.0];

    return result;

    }


    相关文章

      网友评论

          本文标题: 对十六进制颜色的设置

          本文链接:https://www.haomeiwen.com/subject/impvkttx.html