forked from dmorrow/ObjectiveC-Utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUTColor.m
35 lines (28 loc) · 841 Bytes
/
UTColor.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
//
// UTColor.m
// RingFinder
//
// Created by Daniel Morrow on 4/14/10.
// Copyright 2010 Tiffany & Co.. All rights reserved.
//
#import "UTColor.h"
@implementation UTColor
+ (UIColor *)colorWithHex:(UInt32)hex {
int r = (hex >> 16) & 0xFF;
int g = (hex >> 8) & 0xFF;
int b = (hex) & 0xFF;
return [UIColor colorWithRed:r / 255.0f
green:g / 255.0f
blue:b / 255.0f
alpha:1.0f];
}
// Returns a UIColor by scanning the string for a hex number and passing that to +[UIColor colorWithRGBHex:]
// Skips any leading whitespace and ignores any trailing characters
+ (UIColor *)colorWithHexString:(NSString *)stringToConvert
{
NSScanner *scanner = [NSScanner scannerWithString:stringToConvert];
unsigned hexNum;
if (![scanner scanHexInt:&hexNum]) return nil;
return [UTColor colorWithHex:hexNum];
}
@end