1 |
efrain |
1 |
/*
|
|
|
2 |
* Copyright 2017 Google
|
|
|
3 |
*
|
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
|
6 |
* You may obtain a copy of the License at
|
|
|
7 |
*
|
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
9 |
*
|
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
13 |
* See the License for the specific language governing permissions and
|
|
|
14 |
* limitations under the License.
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
#import <TargetConditionals.h>
|
|
|
18 |
#if TARGET_OS_IOS || TARGET_OS_TV
|
|
|
19 |
|
|
|
20 |
#import "FirebaseInAppMessaging/Sources/Util/UIColor+FIRIAMHexString.h"
|
|
|
21 |
|
|
|
22 |
@implementation UIColor (HexString)
|
|
|
23 |
+ (UIColor *)firiam_colorWithHexString:(nullable NSString *)hexString {
|
|
|
24 |
if (hexString.length < 7) {
|
|
|
25 |
return nil;
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
unsigned rgbValue = 0;
|
|
|
29 |
NSScanner *scanner = [NSScanner scannerWithString:hexString];
|
|
|
30 |
[scanner setScanLocation:1]; // bypass '#' character
|
|
|
31 |
|
|
|
32 |
if (![scanner scanHexInt:&rgbValue]) {
|
|
|
33 |
// no valid heximal value is detected
|
|
|
34 |
return nil;
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16) / 255.0
|
|
|
38 |
green:((rgbValue & 0xFF00) >> 8) / 255.0
|
|
|
39 |
blue:(rgbValue & 0xFF) / 255.0
|
|
|
40 |
alpha:1.0];
|
|
|
41 |
}
|
|
|
42 |
@end
|
|
|
43 |
|
|
|
44 |
#endif // TARGET_OS_IOS || TARGET_OS_TV
|