forked from wix/react-native-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColor.m
42 lines (29 loc) · 878 Bytes
/
Color.m
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
#import "Color.h"
@interface Color ()
@property(nonatomic, retain) UIColor *value;
@end
@implementation Color
+ (instancetype)withColor:(UIColor *)value {
return [[Color alloc] initWithValue:value];
}
- (instancetype)initWithValue:(UIColor *)value {
return [super initWithValue:value];
}
- (UIColor *)get {
return self.value;
}
- (UIColor *)withDefault:(id)defaultValue {
return [super withDefault:defaultValue];
}
- (NSString *)description {
return [self hexStringFromColor:[self withDefault:nil]];
}
- (NSString *)hexStringFromColor:(UIColor *)color {
const CGFloat *components = CGColorGetComponents(color.CGColor);
CGFloat r = components[0];
CGFloat g = components[1];
CGFloat b = components[2];
return [NSString
stringWithFormat:@"#%02lX%02lX%02lX", lroundf(r * 255), lroundf(g * 255), lroundf(b * 255)];
}
@end