commit | author | age
|
655e66
|
1 |
/* |
H |
2 |
* Copyright (C) 2017 Twitter, Inc. |
|
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 |
|
a0a843
|
18 |
#import <Foundation/Foundation.h> |
H |
19 |
#if IS_UIKIT_AVAILABLE |
|
20 |
#import <UIKit/UIKit.h> |
|
21 |
#else |
|
22 |
#import <Cocoa/Cocoa.h> |
|
23 |
|
|
24 |
// This adds type name compatibility, but definitely not API cmopatibility for these classes. This |
|
25 |
// is really a temporarly workaround to get this code building for OS X. |
|
26 |
typedef NSColor UIColor; |
|
27 |
typedef NSImage UIImage; |
|
28 |
#endif |
|
29 |
|
|
30 |
NS_ASSUME_NONNULL_BEGIN |
|
31 |
|
|
32 |
// Based off of rosetta color palette, |
|
33 |
// see https://svn.twitter.biz/design/main/resources/colors/rosetta_colors.html (go/colors). |
|
34 |
@interface TWTRColorUtil : NSObject |
|
35 |
|
|
36 |
#pragma mark - Black and White |
|
37 |
|
|
38 |
+ (UIColor *)blackColor; |
|
39 |
+ (UIColor *)whiteColor; |
|
40 |
|
|
41 |
#pragma mark - Blues |
|
42 |
|
|
43 |
+ (UIColor *)blueColor; |
|
44 |
+ (UIColor *)blueTextColor; |
|
45 |
+ (UIColor *)lightBlueColor; |
|
46 |
+ (UIColor *)mediumBlueColor; |
|
47 |
+ (UIColor *)darkBlueColor; |
|
48 |
|
|
49 |
#pragma mark - Reds |
|
50 |
|
|
51 |
+ (UIColor *)redColor; |
|
52 |
+ (UIColor *)darkRedColor; |
|
53 |
|
|
54 |
#pragma mark - Purples |
|
55 |
|
|
56 |
+ (UIColor *)darkPurpleColor; |
|
57 |
+ (UIColor *)deepPurpleColor; |
|
58 |
+ (UIColor *)mediumPurpleColor; |
|
59 |
|
|
60 |
#pragma mark - Grays |
|
61 |
|
|
62 |
+ (UIColor *)grayTextColor; |
|
63 |
+ (UIColor *)darkGrayTextColor; |
|
64 |
+ (UIColor *)grayColor; |
|
65 |
+ (UIColor *)borderGrayColor; |
|
66 |
+ (UIColor *)darkBorderGrayColor; |
|
67 |
+ (UIColor *)faintGrayColor; |
|
68 |
+ (UIColor *)mediumGrayColor; |
|
69 |
+ (UIColor *)darkGrayColor; |
|
70 |
|
|
71 |
#pragma mark - Component Colors |
|
72 |
|
|
73 |
+ (UIColor *)textColor; |
|
74 |
+ (UIColor *)imagePlaceholderColor; |
|
75 |
|
|
76 |
#pragma mark - Utilities |
|
77 |
|
|
78 |
+ (NSInteger)hexWithColor:(UIColor *)color; |
|
79 |
+ (UIColor *)colorFromHex:(NSInteger)hex; |
|
80 |
|
|
81 |
+ (UIImage *)imageWithColor:(UIColor *)color; |
|
82 |
+ (BOOL)isLightColor:(UIColor *)color; |
|
83 |
+ (BOOL)isLightColor:(UIColor *)color lightnessThreshold:(CGFloat)lightnessThreshold; |
|
84 |
|
|
85 |
+ (BOOL)isOpaqueColor:(UIColor *)color; |
|
86 |
|
|
87 |
#pragma mark - Color calculations |
|
88 |
|
|
89 |
/** |
|
90 |
* Returns a secondary text color by |
|
91 |
* a) picking an alpha component based on whether the background color is light |
|
92 |
* b) applying that alpha component to the primary text color |
|
93 |
*/ |
|
94 |
+ (UIColor *)secondaryTextColorFromPrimaryTextColor:(UIColor *)primaryTextColor backgroundColor:(UIColor *)backgroundColor; |
|
95 |
|
|
96 |
/** |
|
97 |
* Returns a media background color by |
|
98 |
* a) picking an alpha component based on whether the background color is light |
|
99 |
* b) applying that alpha component to either solid white or black, based on the background |
|
100 |
*/ |
|
101 |
+ (UIColor *)mediaBackgroundColorFromBackgroundColor:(UIColor *)backgroundColor; |
|
102 |
|
|
103 |
/** |
|
104 |
* Returns a logo color appropriate for the background color. |
|
105 |
*/ |
|
106 |
+ (UIColor *)logoColorFromBackgroundColor:(UIColor *)backgroundColor; |
|
107 |
|
|
108 |
/** |
|
109 |
* Returns a color for the text of a button given its background |
|
110 |
* color. This is intended for use in buttons or to highlight text. |
|
111 |
* |
|
112 |
* @param backgroundColor Background color where the text is displayed. |
|
113 |
* |
|
114 |
* @return Color of the text. |
|
115 |
*/ |
|
116 |
+ (UIColor *)contrastingTextColorFromBackgroundColor:(UIColor *)backgroundColor; |
|
117 |
|
|
118 |
/** |
|
119 |
* Returns a darker color based on the original color and a percent to darken. |
|
120 |
* |
|
121 |
* @param color The original color |
|
122 |
* @param lightnessLevel Lightness levels to lighten. Capped to 0 and 1.0. |
|
123 |
*/ |
|
124 |
+ (UIColor *)darkerColorForColor:(UIColor *)color lightnessLevel:(CGFloat)lightnessLevel; |
|
125 |
|
|
126 |
/** |
|
127 |
* Returns a darker color based on the original color and a percent to lighten. |
|
128 |
* |
|
129 |
* @param color The original color |
|
130 |
* @param lightnessLevel Lightness levels to lighten. Capped to 0 and 1.0. |
|
131 |
*/ |
|
132 |
+ (UIColor *)lighterColorForColor:(UIColor *)color lightnessLevel:(CGFloat)lightnessLevel; |
|
133 |
|
|
134 |
@end |
|
135 |
|
|
136 |
NS_ASSUME_NONNULL_END |