博客> iOS 颜色值#ffffff转UIColor
iOS 颜色值#ffffff转UIColor
2018-11-11 11:49 评论:0 阅读:921 peacekzt
ios UIColor
  • (UIColor )colorWithHexString:(NSString )string { if([stringToConverthasPrefix:@"#"]){ stringToConvert = [string substringFromIndex:1]; }

    NSScanner*scanner = [NSScanner scannerWithString:string]; unsigned hexNum; if(![scanner scanHexInt:&hexNum]){ returnnil; }

    return[UIColor colorWithRGBHex:hexNum]; }

  • (UIColor *)colorWithRGBHex:(UInt32)hex { int r = (hex >>16) &0xFF; int g = (hex >>8) &0xFF; int b = (hex) &0xFF; return [UIColor colorWithRed:r /255.0f green:g /255.0f blue:b /255.0f alpha:1.0f]; }
收藏
0
sina weixin mail 回到顶部