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