首页 > 代码库 > iOS 设置RGB色的宏
iOS 设置RGB色的宏
转自:http://lizhuang.iteye.com/blog/1931768
?//RGB Color macro #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] //RGB color macro with alpha #define UIColorFromRGBWithAlpha(rgbValue,a) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:a] //16进制字符串 转换为int + (id)colorWithHex:(NSString *)hex alpha:(CGFloat)alpha { NSAssert(7 == hex.length, @"Hex color format error!"); unsigned color = 0; NSScanner *hexValueScanner = [NSScanner scannerWithString:[hex substringFromIndex:1]]; [hexValueScanner scanHexInt:&color]; int blue = color & 0xFF; int green = (color >> 8) & 0xFF; int red = (color >> 16) & 0xFF; return [UIColor colorWithRed:red/255.0 green:green/255.0 blue:blue/255.0 alpha:1.0]; } ?
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。