美文网首页工具类
IOS 颜色值#ffffff转UIColor

IOS 颜色值#ffffff转UIColor

作者: Mr_Luo | 来源:发表于2016-01-23 09:42 被阅读1793次
+ (UIColor*)colorWithHexString:(NSString*)stringToConvert{
    if([stringToConverthasPrefix:@"#"])
    {
        stringToConvert = [stringToConvertsubstringFromIndex:1];
    }
    NSScanner*scanner = [NSScannerscannerWithString:stringToConvert];
    unsignedhexNum;
    if(![scannerscanHexInt:&hexNum])
    {
        returnnil;
    }
    return[UIColorcolorWithRGBHex:hexNum];
}

+ (UIColor*)colorWithRGBHex:(UInt32)hex{
    intr = (hex >>16) &0xFF;
    intg = (hex >>8) &0xFF;
    intb = (hex) &0xFF;
    return[UIColorcolorWithRed:r /255.0f
    green:g /255.0f
    blue:b /255.0f
    alpha:1.0f];
}

相关文章

网友评论

  • 马爷:不错不错 很赞 很需要

本文标题:IOS 颜色值#ffffff转UIColor

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