如何从十六进制字符串创建UIColor?如何创建UIColor从十六进制字符串格式,如#00FF00?
3 回答
鸿蒙传说
TA贡献1865条经验 获得超7个赞
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#define UIColorFromRGB(rgbValue) \[UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \ green:((float)((rgbValue & 0x00FF00) >> 8))/255.0 \ blue:((float)((rgbValue & 0x0000FF) >> 0))/255.0 \ alpha:1.0]
label.textColor = UIColorFromRGB(0xBC1128);
慕田峪4524236
TA贡献1875条经验 获得超5个赞
// Assumes input like "#00FF00" (#RRGGBB).+ (UIColor *)colorFromHexString:(NSString *)hexString { unsigned rgbValue = 0; NSScanner *scanner = [NSScanner scannerWithString:hexString]; [scanner setScanLocation:1]; // bypass '#' character [scanner scanHexInt:&rgbValue]; return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0];}
- 3 回答
- 0 关注
- 539 浏览
添加回答
举报
0/150
提交
取消