Created
August 11, 2020 10:33
-
-
Save riscait/b1242c43097998eda289635cb2c94fd3 to your computer and use it in GitHub Desktop.
Dark-mode compatible UIColor extension with Objective-C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
NS_ASSUME_NONNULL_BEGIN | |
@interface UIColor (Ext) | |
// Original Colors | |
+ (UIColor *) primary; | |
// Compatible System Colors for iOS 12 and below | |
+ (UIColor *) label; | |
+ (UIColor *) secondaryLabel; | |
+ (UIColor *) tertiaryLabel; | |
+ (UIColor *) quaternaryLabel; | |
+ (UIColor *) systemFill; | |
+ (UIColor *) secondarySystemFill; | |
+ (UIColor *) tertiarySystemFill; | |
+ (UIColor *) quaternarySystemFill; | |
+ (UIColor *) placeholderText; | |
+ (UIColor *) systemBackground; | |
+ (UIColor *) secondarySystemBackground; | |
+ (UIColor *) tertiarySystemBackground; | |
+ (UIColor *) systemGroupedBackground; | |
+ (UIColor *) secondarySystemGroupedBackground; | |
+ (UIColor *) tertiarySystemGroupedBackground; | |
+ (UIColor *) separator; | |
+ (UIColor *) opaqueSeparator; | |
+ (UIColor *) link; | |
+ (UIColor *) darkText; | |
+ (UIColor *) lightText; | |
+ (UIColor *) systemBlue; | |
+ (UIColor *) systemGreen; | |
+ (UIColor *) systemIndigo; | |
+ (UIColor *) systemOrange; | |
+ (UIColor *) systemPink; | |
+ (UIColor *) systemPurple; | |
+ (UIColor *) systemRed; | |
+ (UIColor *) systemTeal; | |
+ (UIColor *) systemYellow; | |
+ (UIColor *) systemGray; | |
+ (UIColor *) systemGray2; | |
+ (UIColor *) systemGray3; | |
+ (UIColor *) systemGray4; | |
+ (UIColor *) systemGray5; | |
+ (UIColor *) systemGray6; | |
@end | |
NS_ASSUME_NONNULL_END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "UIColor+Ext.h" | |
@implementation UIColor (Ext) | |
+ (UIColor *) primary { | |
return [UIColor colorNamed:@"Primary"]; | |
} | |
+ (UIColor *) label { | |
if (@available(iOS 13, *)) { | |
return UIColor.labelColor; | |
} else { | |
return UIColor.blackColor; | |
} | |
} | |
+ (UIColor *) secondaryLabel { | |
if (@available(iOS 13, *)) { | |
return UIColor.secondaryLabelColor; | |
} else { | |
return [UIColor colorWithRed:60.0/255 green:60.0/255 blue:67.0/255 alpha:0.6]; | |
} | |
} | |
+ (UIColor *) tertiaryLabel { | |
if (@available(iOS 13, *)) { | |
return UIColor.tertiaryLabelColor; | |
} else { | |
return [UIColor colorWithRed:60.0/255 green:60.0/255 blue:67.0/255 alpha:0.3]; | |
} | |
} | |
+ (UIColor *) quaternaryLabel { | |
if (@available(iOS 13, *)) { | |
return UIColor.quaternaryLabelColor; | |
} else { | |
return [UIColor colorWithRed:60.0/255 green:60.0/255 blue:67.0/255 alpha:0.18]; | |
} | |
} | |
+ (UIColor *) systemFill { | |
if (@available(iOS 13, *)) { | |
return UIColor.systemFillColor; | |
} else { | |
return [UIColor colorWithRed:120.0/255 green:120.0/255 blue:128.0/255 alpha:0.2]; | |
} | |
} | |
+ (UIColor *) secondarySystemFill { | |
if (@available(iOS 13, *)) { | |
return UIColor.secondarySystemFillColor; | |
} else { | |
return [UIColor colorWithRed:120.0/255 green:120.0/255 blue:128.0/255 alpha:0.16]; | |
} | |
} | |
+ (UIColor *) tertiarySystemFill { | |
if (@available(iOS 13, *)) { | |
return UIColor.tertiarySystemFillColor; | |
} else { | |
return [UIColor colorWithRed:118.0/255 green:118.0/255 blue:128.0/255 alpha:0.12]; | |
} | |
} | |
+ (UIColor *) quaternarySystemFill { | |
if (@available(iOS 13, *)) { | |
return UIColor.quaternarySystemFillColor; | |
} else { | |
return [UIColor colorWithRed:116.0/255 green:116.0/255 blue:128.0/255 alpha:0.08]; | |
} | |
} | |
+ (UIColor *) placeholderText { | |
if (@available(iOS 13, *)) { | |
return UIColor.placeholderTextColor; | |
} else { | |
return [UIColor colorWithRed:60.0/255 green:60.0/255 blue:67.0/255 alpha:0.3]; | |
} | |
} | |
+ (UIColor *) systemBackground { | |
if (@available(iOS 13, *)) { | |
return UIColor.systemBackgroundColor; | |
} else { | |
return UIColor.whiteColor; | |
} | |
} | |
+ (UIColor *) secondarySystemBackground { | |
if (@available(iOS 13, *)) { | |
return UIColor.secondarySystemBackgroundColor; | |
} else { | |
return [UIColor colorWithRed:242.0/255 green:242.0/255 blue:247.0/255 alpha:1.0]; | |
} | |
} | |
+ (UIColor *) tertiarySystemBackground { | |
if (@available(iOS 13, *)) { | |
return UIColor.tertiarySystemBackgroundColor; | |
} else { | |
return [UIColor colorWithRed:255.0/255 green:255.0/255 blue:255.0/255 alpha:1.0]; | |
} | |
} | |
+ (UIColor *) systemGroupedBackground { | |
if (@available(iOS 13, *)) { | |
return UIColor.systemGroupedBackgroundColor; | |
} else { | |
return [UIColor colorWithRed:242.0/255 green:242.0/255 blue:247.0/255 alpha:1.0]; | |
} | |
} | |
+ (UIColor *) secondarySystemGroupedBackground { | |
if (@available(iOS 13, *)) { | |
return UIColor.secondarySystemGroupedBackgroundColor; | |
} else { | |
return [UIColor colorWithRed:255.0/255 green:255.0/255 blue:255.0/255 alpha:1.0]; | |
} | |
} | |
+ (UIColor *) tertiarySystemGroupedBackground { | |
if (@available(iOS 13, *)) { | |
return UIColor.tertiarySystemGroupedBackgroundColor; | |
} else { | |
return [UIColor colorWithRed:242.0/255 green:242.0/255 blue:247.0/255 alpha:1.0]; | |
} | |
} | |
+ (UIColor *) separator { | |
if (@available(iOS 13, *)) { | |
return UIColor.separatorColor; | |
} else { | |
return [UIColor colorWithRed:60.0/255 green:60.0/255 blue:67.0/255 alpha:0.29]; | |
} | |
} | |
+ (UIColor *) opaqueSeparator { | |
if (@available(iOS 13, *)) { | |
return UIColor.opaqueSeparatorColor; | |
} else { | |
return [UIColor colorWithRed:198.0/255 green:198.0/255 blue:200.0/255 alpha:1.0]; | |
} | |
} | |
+ (UIColor *) link { | |
if (@available(iOS 13, *)) { | |
return UIColor.linkColor; | |
} else { | |
return [UIColor colorWithRed:0.0/255 green:122.0/255 blue:255.0/255 alpha:1.0]; | |
} | |
} | |
+ (UIColor *) darkText { | |
if (@available(iOS 13, *)) { | |
return UIColor.darkTextColor; | |
} else { | |
return [UIColor colorWithRed:0.0/255 green:0.0/255 blue:0.0/255 alpha:1.0]; | |
} | |
} | |
+ (UIColor *) lightText { | |
if (@available(iOS 13, *)) { | |
return UIColor.lightTextColor; | |
} else { | |
return [UIColor colorWithRed:255.0/255 green:255.0/255 blue:255.0/255 alpha:0.6]; | |
} | |
} | |
+ (UIColor *) systemBlue { | |
if (@available(iOS 13, *)) { | |
return UIColor.systemBlueColor; | |
} else { | |
return [UIColor colorWithRed:0.0/255 green:122.0/255 blue:255.0/255 alpha:1.0]; | |
} | |
} | |
+ (UIColor *) systemGreen { | |
if (@available(iOS 13, *)) { | |
return UIColor.systemGreenColor; | |
} else { | |
return [UIColor colorWithRed:52.0/255 green:199.0/255 blue:89.0/255 alpha:1.0]; | |
} | |
} | |
+ (UIColor *) systemIndigo { | |
if (@available(iOS 13, *)) { | |
return UIColor.systemBlueColor; | |
} else { | |
return [UIColor colorWithRed:88.0/255 green:86.0/255 blue:214.0/255 alpha:1.0]; | |
} | |
} | |
+ (UIColor *) systemOrange { | |
if (@available(iOS 13, *)) { | |
return UIColor.systemOrangeColor; | |
} else { | |
return [UIColor colorWithRed:255.0/255 green:149.0/255 blue:0.0/255 alpha:1.0]; | |
} | |
} | |
+ (UIColor *) systemPink { | |
if (@available(iOS 13, *)) { | |
return UIColor.systemPinkColor; | |
} else { | |
return [UIColor colorWithRed:255.0/255 green:45.0/255 blue:85.0/255 alpha:1.0]; | |
} | |
} | |
+ (UIColor *) systemPurple { | |
if (@available(iOS 13, *)) { | |
return UIColor.systemPurpleColor; | |
} else { | |
return [UIColor colorWithRed:175.0/255 green:82.0/255 blue:222.0/255 alpha:1.0]; | |
} | |
} | |
+ (UIColor *) systemRed { | |
if (@available(iOS 13, *)) { | |
return UIColor.systemRedColor; | |
} else { | |
return [UIColor colorWithRed:255.0/255 green:59.0/255 blue:48.0/255 alpha:1.0]; | |
} | |
} | |
+ (UIColor *) systemTeal { | |
if (@available(iOS 13, *)) { | |
return UIColor.systemTealColor; | |
} else { | |
return [UIColor colorWithRed:90.0/255 green:200.0/255 blue:250.0/255 alpha:1.0]; | |
} | |
} | |
+ (UIColor *) systemYellow { | |
if (@available(iOS 13, *)) { | |
return UIColor.systemYellowColor; | |
} else { | |
return [UIColor colorWithRed:255.0/255 green:204.0/255 blue:0.0/255 alpha:1.0]; | |
} | |
} | |
+ (UIColor *) systemGray { | |
if (@available(iOS 13, *)) { | |
return UIColor.systemGrayColor; | |
} else { | |
return [UIColor colorWithRed:142.0/255 green:142.0/255 blue:147.0/255 alpha:1.0]; | |
} | |
} | |
+ (UIColor *) systemGray2 { | |
if (@available(iOS 13, *)) { | |
return UIColor.systemGray2Color; | |
} else { | |
return [UIColor colorWithRed:174.0/255 green:174.0/255 blue:178.0/255 alpha:1.0]; | |
} | |
} | |
+ (UIColor *) systemGray3 { | |
if (@available(iOS 13, *)) { | |
return UIColor.systemGray3Color; | |
} else { | |
return [UIColor colorWithRed:72.0/255 green:72.0/255 blue:74.0/255 alpha:1.0]; | |
} | |
} | |
+ (UIColor *) systemGray4 { | |
if (@available(iOS 13, *)) { | |
return UIColor.systemGray4Color; | |
} else { | |
return [UIColor colorWithRed:58.0/255 green:58.0/255 blue:60.0/255 alpha:1.0]; | |
} | |
} | |
+ (UIColor *) systemGray5 { | |
if (@available(iOS 13, *)) { | |
return UIColor.systemGray5Color; | |
} else { | |
return [UIColor colorWithRed:44.0/255 green:44.0/255 blue:46.0/255 alpha:1.0]; | |
} | |
} | |
+ (UIColor *) systemGray6 { | |
if (@available(iOS 13, *)) { | |
return UIColor.systemGray6Color; | |
} else { | |
return [UIColor colorWithRed:28.0/255 green:28.0/255 blue:30.0/255 alpha:1.0]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment