//十六进制转rgb
#define ColorWithHexString(hexString) [UIColor colorWithHexString:hexString]
// 获取RGB颜色
#define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
#define RGB(r,g,b) RGBA(r,g,b,1.0f)
//字体颜色
#define TITLE_EA_COLOR RGB(51,51,51)
#define TITLE_CD_COLOR RGB(34, 34, 34)
#define TITLE_AEC_COLOR RGB(153,153,153)
#define VIEW_BDA_COLOR RGB(241,241,241)
#define SELECT_LINE_Color RGB(216,0,8)
#define SELECT_TITLE_Color RGB(58,58,58)
#define Button_COLOR1 RGB(51,51,51)
#define LINE_COLOR RGB(168,168,168)
//颜色
#define ColorHex_333333 ColorWithHexString(@"#333333")
#define ColorHex_444444 ColorWithHexString(@"#444444")
#define ColorHex_666666 ColorWithHexString(@"#666666")
#define ColorHex_D9261C ColorWithHexString(@"#D9261C")
#define ColorHex_CCCCCC ColorWithHexString(@"#CCCCCC")//80 80 80
#import "UIColor+Tool.h"
@implementation UIColor (Tool)
//十六进制 # 十进制转 0X RGB
+(UIColor *)colorWithHexString: (NSString *)color
{
NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
// String should be 6 or 8 characters
if ([cString length] < 6) {
return [UIColor clearColor];
}
// 判断前缀
if ([cString hasPrefix:@"0X"])
cString = [cString substringFromIndex:2];
if ([cString hasPrefix:@"#"])
cString = [cString substringFromIndex:1];
if ([cString length] != 6)
return [UIColor clearColor];
// 从六位数值中找到RGB对应的位数并转换
NSRange range;
range.location = 0;
range.length = 2;
//R、G、B
NSString *rString = [cString substringWithRange:range];
range.location = 2;
NSString *gString = [cString substringWithRange:range];
range.location = 4;
NSString *bString = [cString substringWithRange:range];
// Scan values
unsigned int r, g, b;
[[NSScanner scannerWithString:rString] scanHexInt:&r];
[[NSScanner scannerWithString:gString] scanHexInt:&g];
[[NSScanner scannerWithString:bString] scanHexInt:&b];
return [UIColor colorWithRed:((float) r / 255.0f) green:((float) g / 255.0f) blue:((float) b / 255.0f) alpha:1.0f];
}
@end