4
This commit is contained in:
@@ -12,6 +12,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@interface UIColor (Extension)
|
||||
+ (UIColor *)colorWithHex:(int)hexValue;
|
||||
+ (nullable UIColor *)colorWithHexString:(NSString *)hexString;
|
||||
+ (UIColor *)kb_dynamicColorWithLightColor:(UIColor *)lightColor
|
||||
darkColor:(UIColor *)darkColor;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
@@ -41,4 +41,19 @@
|
||||
int rgb = (int)(value & 0xFFFFFF);
|
||||
return [UIColor colorWithHex:rgb alpha:alpha];
|
||||
}
|
||||
|
||||
+ (UIColor *)kb_dynamicColorWithLightColor:(UIColor *)lightColor
|
||||
darkColor:(UIColor *)darkColor {
|
||||
UIColor *light = lightColor ?: [UIColor blackColor];
|
||||
UIColor *dark = darkColor ?: light;
|
||||
if (@available(iOS 13.0, *)) {
|
||||
return [UIColor colorWithDynamicProvider:^UIColor *_Nonnull(UITraitCollection *_Nonnull traitCollection) {
|
||||
if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
|
||||
return dark;
|
||||
}
|
||||
return light;
|
||||
}];
|
||||
}
|
||||
return light;
|
||||
}
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user