网上查了 很多都是编写复杂 装换函数 非常臃肿。
我在项目中采用 宏定义实现。不敢独享 特别分享。希望有参考价值。
#define HEX_RGBA(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)]
#define HEX_RGB(rgbValue)[UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:(1)]
#define RGB(R,G,B) [UIColor colorWithRed:R/255.0f green:G/255.0f blue:B/255.0f alpha:1.0f]
#define RGBA(R,G,B,A) [UIColor colorWithRed:R/255.0f green:G/255.0f blue:B/255.0f alpha:A]
具体调用
UILabel *addressLbl = [UILabel smt_labelWithText:@"" textColor:HEX_RGB(0x8e94bb) font:MEDIUMSYSTEMFONT(11)];
addressLbl.textAlignment = NSTextAlignmentRight;