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