ITeye博客

颜色设置

修博龙泉 · 2013-04-27 09:50 · ios开发学习相关 · 移动开发 · Markdown


[globle colorfromhexrgb:@"bb0b15"]
+ (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;
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。