forked from ishkawa/UIColor-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIColor+Code.m
More file actions
27 lines (20 loc) · 928 Bytes
/
UIColor+Code.m
File metadata and controls
27 lines (20 loc) · 928 Bytes
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
#import "UIColor+Code.h"
@implementation UIColor (Code)
+ (UIColor *)colorWithCode:(NSString *)code
{
code = [code stringByReplacingOccurrencesOfString:@"#" withString:@""];
NSString *redString = [code substringWithRange:NSMakeRange(0, 2)];
NSString *greenString = [code substringWithRange:NSMakeRange(2, 2)];
NSString *blueString = [code substringWithRange:NSMakeRange(4, 2)];
NSUInteger redValue;
NSUInteger greenValue;
NSUInteger blueValue;
[[NSScanner scannerWithString:redString] scanHexInt:&redValue];
[[NSScanner scannerWithString:greenString] scanHexInt:&greenValue];
[[NSScanner scannerWithString:blueString] scanHexInt:&blueValue];
return [UIColor colorWithRed:(CGFloat)redValue/255.f
green:(CGFloat)greenValue/255.f
blue:(CGFloat)blueValue/255.f
alpha:1.f];
}
@end