LSGColor.m
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#import <UIKit/UIKit.h>
#import "LSGColor.h"
@implementation LSGColor
+ (UIColor *)colorWithHexValue:(NSInteger)color alpha:(CGFloat)alpha {
return [UIColor colorWithRed:((float) ((color & 0xff0000) >> 16)) / 255.0
green:((float) ((color & 0x00ff00) >> 8)) / 255.0
blue:((float) (color & 0x0000ff)) / 255.0
alpha:alpha];
}
+ (UIColor *)colorWithHexString:(NSString *)stringToConvert
{
//去掉前后空格换行符
NSString *cString = [[stringToConvert stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
if ([cString hasPrefix:@"0X"])
cString = [cString substringFromIndex:2];
else if ([cString hasPrefix:@"#"])
cString = [cString substringFromIndex:1];
if ([cString length] != 6)
return nil;
// Separate into r, g, b substrings
NSRange range;
range.location = 0;
range.length = 2;
NSString *rString = [cString substringWithRange:range];
range.location = 2;
NSString *gString = [cString substringWithRange:range];
range.location = 4;
NSString *bString = [cString substringWithRange:range];
unsigned int r, g, b;
[[NSScanner scannerWithString:rString] scanHexInt:&r];
[[NSScanner scannerWithString:gString] scanHexInt:&g];
[[NSScanner scannerWithString:bString] scanHexInt:&b];
return [UIColor colorWithRed:r / 255.0 green:g / 255.0 blue:b / 255.0 alpha:1.0];
}
+ (UIColor *)backgroudColor
{
return [UIColor whiteColor]; //[UIColor whiteColor];
}
+ (UIColor *)textColor
{
return [self colorWithHexValue:0x3E3E3E alpha:1.0];
}
+ (UIColor *)lightTextColor
{
return [self colorWithHexValue:0x7E7E7E alpha:1.0];
}
+ (UIColor *)redColor
{
return [self colorWithHexValue:0xD11301 alpha:1.0];
}
+ (UIColor *)borderColor
{
return [self colorWithHexValue:0xeeeeee alpha:1.0];
}
@end