diff --git a/CSColorPicker Resources/CSColorPicker/CSColorPicker.h b/CSColorPicker Resources/CSColorPicker/CSColorPicker.h index 849dc64..9360dd3 100644 --- a/CSColorPicker Resources/CSColorPicker/CSColorPicker.h +++ b/CSColorPicker Resources/CSColorPicker/CSColorPicker.h @@ -3,5 +3,5 @@ // Copyright (c) 2016 - 2019 CreatureCoding. All rights reserved. // -#import "UIColor+CSColorPicker.h" -#import "NSString+CSColorPicker.h" +#import "Categories/UIColor+CSColorPicker.h" +#import "Categories/NSString+CSColorPicker.h" diff --git a/CSColorPicker Resources/CSColorPicker/NSString+CSColorPicker.h b/CSColorPicker Resources/CSColorPicker/NSString+CSColorPicker.h index ab23f6d..a57bd34 100644 --- a/CSColorPicker Resources/CSColorPicker/NSString+CSColorPicker.h +++ b/CSColorPicker Resources/CSColorPicker/NSString+CSColorPicker.h @@ -11,6 +11,14 @@ // @interface NSString (CSColorPicker) +// +// same as csp_colorFromHexString: returning a dynamic color +// if the hex string is not dynamic, this will fallback to cscp_colorFromHexString: +// supported formats include 'l:RGB d:RGB', 'l:ARGB d:ARGB', 'l:RRGGBB d:RRGGBB', 'l:AARRGGBB d:AARRGGBB', 'l:RGB:0.500000 d:RGB:0.500000', 'l:RRGGBB:0.500000 d:RRGGBB:0.500000' +// all formats work with or without # +// ++ (UIColor *)cscp_dynamicColorFromHexString:(NSString *)hexString; + // // returns a UIColor from the hex string eg [UIColor cscp_colorFromHexString:@"#FF0000"]; // if the hex string is invalid, returns red @@ -23,6 +31,11 @@ // returns true if the string is a valid hex (will pass with or without #) + (BOOL)cscp_isValidHexString:(NSString *)hexString; +// +// returns a string dynamic hex string representation of the string instance +// +- (UIColor *)cscp_dynamicHexColor; + // // returns a string hex string representation of the string instance // diff --git a/CSColorPicker Resources/CSColorPicker/UIColor+CSColorPicker.h b/CSColorPicker Resources/CSColorPicker/UIColor+CSColorPicker.h index e003571..8452ecf 100644 --- a/CSColorPicker Resources/CSColorPicker/UIColor+CSColorPicker.h +++ b/CSColorPicker Resources/CSColorPicker/UIColor+CSColorPicker.h @@ -2,7 +2,6 @@ // Created by CreatureSurvive on 3/17/17. // Copyright (c) 2016 - 2019 CreatureCoding. All rights reserved. // - #import @interface UIColor (CSColorPicker) @@ -15,6 +14,16 @@ // + (UIColor *)cscp_colorFromHexString:(NSString *)hexString; +// +// returns a NSString representation of a UIColor in hex format eg [UIColor cscp_dynamicHexStringFromColor:[UIColor redColor]]; outputs @"l:#FF0000 d:#FF0000" +// ++ (NSString *)cscp_dynamicHexStringFromColor: (UIColor *)color; + +// +// returns a NSString representation of a UIColor in hex format eg [UIColor cscp_dynamicHexStringFromColor:[UIColor redColor] alpha:YES]; outputs @"#l:FFFF0000 d:FFFF0000" +// ++ (NSString *)cscp_dynamicHexStringFromColor: (UIColor *)color alpha:(BOOL)include; + // // returns a NSString representation of a UIColor in hex format eg [UIColor cscp_hexStringFromColor:[UIColor redColor]]; outputs @"#FF0000" // @@ -76,6 +85,16 @@ // - (CGFloat)cscp_brightness; +// +// the dynamic hexString value of the color instance +// +- (NSString *)cscp_dynamicHexString; + +// +// the dynamic hexString value of the color instance with alpha included +// +- (NSString *)cscp_dynamicHexStringWithAlpha; + // // the hexString value of the color instance // diff --git a/CSColorPicker Resources/libCSColorPicker.dylib b/CSColorPicker Resources/libCSColorPicker.dylib index 70ce09c..fdeb9f2 100755 Binary files a/CSColorPicker Resources/libCSColorPicker.dylib and b/CSColorPicker Resources/libCSColorPicker.dylib differ diff --git a/CSColorPicker Resources/libCSPreferences.dylib b/CSColorPicker Resources/libCSPreferences.dylib deleted file mode 100755 index 01a1ad8..0000000 Binary files a/CSColorPicker Resources/libCSPreferences.dylib and /dev/null differ diff --git a/Makefile b/Makefile index 7c7d0f5..357afc6 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,12 @@ ARCHS = armv7 armv7s arm64 arm64e TARGET = iphone:clang:13.0:5.0 -GO_EASY_ON_ME = 0 +DEBUG = 1 FINALPACKAGE = 1 -DEBUG = 0 +LEAN_AND_MEAN = 1 +GO_EASY_ON_ME = 0 -PREFIX = $(THEOS)/toolchains/xcode11.xctoolchain/usr/bin/ -INSTALL_TARGET_PROCESSES = Preferences +INSTALL_TARGET_PROCESSES = Preferences TweakSettings include $(THEOS)/makefiles/common.mk @@ -20,9 +20,22 @@ $(LIBRARY_NAME)_CFLAGS += -fobjc-arc -I$(INCLUDES) -IPrefix.pch include $(THEOS_MAKE_PATH)/library.mk - -# SUBPROJECTS += lcpshim -# include $(THEOS_MAKE_PATH)/aggregate.mk - after-stage:: - $(ECHO_NOTHING)cp "$(THEOS_STAGING_DIR)/usr/lib/libCSColorPicker.dylib" "$(THEOS_PROJECT_DIR)/CSColorPicker Resources/libCSPreferences.dylib"$(ECHO_END) \ No newline at end of file + $(ECHO_NOTHING)mkdir -p "$(THEOS_STAGING_DIR)/usr/include/CSColorPicker"$(ECHO_END) + $(ECHO_NOTHING)cp "$(THEOS_PROJECT_DIR)/source/CSColorPicker.h" "$(THEOS_STAGING_DIR)/usr/include/CSColorPicker/CSColorPicker.h"$(ECHO_END) + $(ECHO_NOTHING)cp "$(THEOS_PROJECT_DIR)/source/Categories/UIColor+CSColorPicker.h" "$(THEOS_STAGING_DIR)/usr/include/CSColorPicker/UIColor+CSColorPicker.h"$(ECHO_END) + $(ECHO_NOTHING)cp "$(THEOS_PROJECT_DIR)/source/Categories/NSString+CSColorPicker.h" "$(THEOS_STAGING_DIR)/usr/include/CSColorPicker/NSString+CSColorPicker.h"$(ECHO_END) + + $(ECHO_NOTHING)mkdir -p "$(THEOS_PROJECT_DIR)/CSColorPicker Resources/CSColorPicker"$(ECHO_END) + $(ECHO_NOTHING)cp "$(THEOS_STAGING_DIR)/usr/lib/libCSColorPicker.dylib" "$(THEOS_PROJECT_DIR)/CSColorPicker Resources/libCSColorPicker.dylib"$(ECHO_END) + $(ECHO_NOTHING)cp "$(THEOS_PROJECT_DIR)/source/CSColorPicker.h" "$(THEOS_PROJECT_DIR)/CSColorPicker Resources/CSColorPicker/CSColorPicker.h"$(ECHO_END) + $(ECHO_NOTHING)cp "$(THEOS_PROJECT_DIR)/source/Categories/UIColor+CSColorPicker.h" "$(THEOS_PROJECT_DIR)/CSColorPicker Resources/CSColorPicker/UIColor+CSColorPicker.h"$(ECHO_END) + $(ECHO_NOTHING)cp "$(THEOS_PROJECT_DIR)/source/Categories/NSString+CSColorPicker.h" "$(THEOS_PROJECT_DIR)/CSColorPicker Resources/CSColorPicker/NSString+CSColorPicker.h"$(ECHO_END) + $(ECHO_NOTHING)zip "$(THEOS_PROJECT_DIR)/CSColorPicker Resources.zip" "$(THEOS_PROJECT_DIR)/CSColorPicker Resources"$(ECHO_END) + + $(ECHO_NOTHING)mkdir -p "$(THEOS)/include/CSColorPicker"$(ECHO_END) + $(ECHO_NOTHING)cp "$(THEOS_STAGING_DIR)/usr/lib/libCSColorPicker.dylib" "$(THEOS)/lib/libCSColorPicker.dylib"$(ECHO_END) + $(ECHO_NOTHING)cp "$(THEOS_PROJECT_DIR)/source/CSColorPicker.h" "$(THEOS)/include/CSColorPicker/CSColorPicker.h"$(ECHO_END) + $(ECHO_NOTHING)cp "$(THEOS_PROJECT_DIR)/source/Categories/UIColor+CSColorPicker.h" "$(THEOS)/include/CSColorPicker/UIColor+CSColorPicker.h"$(ECHO_END) + $(ECHO_NOTHING)cp "$(THEOS_PROJECT_DIR)/source/Categories/NSString+CSColorPicker.h" "$(THEOS)/include/CSColorPicker/NSString+CSColorPicker.h"$(ECHO_END) + \ No newline at end of file diff --git a/control b/control index fd8b257..284041f 100644 --- a/control +++ b/control @@ -1,7 +1,7 @@ Package: com.creaturesurvive.libcscolorpicker Name: libCSColorPicker Pre-Depends: firmware (>= 7.0) -Version: 1.0.5 +Version: 1.0.6 Architecture: iphoneos-arm Description: A minimal color picker library for developers Maintainer: CreatureSurvive diff --git a/source/Categories/NSString+CSColorPicker.h b/source/Categories/NSString+CSColorPicker.h index ab23f6d..a57bd34 100644 --- a/source/Categories/NSString+CSColorPicker.h +++ b/source/Categories/NSString+CSColorPicker.h @@ -11,6 +11,14 @@ // @interface NSString (CSColorPicker) +// +// same as csp_colorFromHexString: returning a dynamic color +// if the hex string is not dynamic, this will fallback to cscp_colorFromHexString: +// supported formats include 'l:RGB d:RGB', 'l:ARGB d:ARGB', 'l:RRGGBB d:RRGGBB', 'l:AARRGGBB d:AARRGGBB', 'l:RGB:0.500000 d:RGB:0.500000', 'l:RRGGBB:0.500000 d:RRGGBB:0.500000' +// all formats work with or without # +// ++ (UIColor *)cscp_dynamicColorFromHexString:(NSString *)hexString; + // // returns a UIColor from the hex string eg [UIColor cscp_colorFromHexString:@"#FF0000"]; // if the hex string is invalid, returns red @@ -23,6 +31,11 @@ // returns true if the string is a valid hex (will pass with or without #) + (BOOL)cscp_isValidHexString:(NSString *)hexString; +// +// returns a string dynamic hex string representation of the string instance +// +- (UIColor *)cscp_dynamicHexColor; + // // returns a string hex string representation of the string instance // diff --git a/source/Categories/NSString+CSColorPicker.m b/source/Categories/NSString+CSColorPicker.m index eec5647..36f80ac 100644 --- a/source/Categories/NSString+CSColorPicker.m +++ b/source/Categories/NSString+CSColorPicker.m @@ -5,6 +5,7 @@ #import "NSString+CSColorPicker.h" #import +#import struct CGFloat; @interface NSString (Private) @@ -15,7 +16,45 @@ + (CGFloat)_cscp_colorComponentFrom:(NSString *)string start:(NSUInteger)start l @implementation NSString (CSColorPicker) -+ (UIColor *)cscp_colorFromHexString:(NSString *)hexString { ++ (UIColor *)cscp_dynamicColorFromHexString:(NSString *)hexString { + + if (!hexString || !hexString.length) return [UIColor redColor]; + + if (![hexString containsString:@" "] || ![hexString.lowercaseString containsString:@"l:"] || ![hexString.lowercaseString containsString:@"d:"]) { + return [self _cscp_colorFromHexString:hexString]; + } + + NSArray *components = [hexString componentsSeparatedByString:@" "]; + + if (!components || !components.count) { + return [self _cscp_colorFromHexString:hexString]; + } + + UIColor *light = [self _cscp_colorFromHexString:[components.firstObject substringFromIndex:2]]; + + if (@available(iOS 13.0, *)) { + UIColor *dark = [self _cscp_colorFromHexString:[components.lastObject substringFromIndex:2]]; + return [UIColor colorWithDynamicProvider:^UIColor * (UITraitCollection *traitCollection) { + switch (traitCollection.userInterfaceStyle) { + case UIUserInterfaceStyleUnspecified: + case UIUserInterfaceStyleLight: + return light; + case UIUserInterfaceStyleDark: + return dark; + } + return light; + }]; + } + + return light; + +} + ++ (UIColor *)cscp_colorFromHexString:(NSString *)hexString { + return [self _cscp_colorFromHexString:hexString]; +} + ++ (UIColor *)_cscp_colorFromHexString:(NSString *)hexString { NSString *colorString = [[hexString stringByReplacingOccurrencesOfString:@"#" withString:@""] uppercaseString]; CGFloat alpha, red, blue, green; @@ -75,6 +114,10 @@ + (BOOL)cscp_isValidHexString:(NSString *)hexString { return (NSNotFound == [[[hexString stringByReplacingOccurrencesOfString:@"#" withString:@""] uppercaseString] rangeOfCharacterFromSet:hexChars].location); } +- (UIColor *)cscp_dynamicHexColor { + return [NSString cscp_dynamicColorFromHexString:self]; +} + - (UIColor *)cscp_hexColor { return [NSString cscp_colorFromHexString:self]; } diff --git a/source/Categories/UIColor+CSColorPicker.h b/source/Categories/UIColor+CSColorPicker.h index dfc665a..8452ecf 100644 --- a/source/Categories/UIColor+CSColorPicker.h +++ b/source/Categories/UIColor+CSColorPicker.h @@ -14,6 +14,16 @@ // + (UIColor *)cscp_colorFromHexString:(NSString *)hexString; +// +// returns a NSString representation of a UIColor in hex format eg [UIColor cscp_dynamicHexStringFromColor:[UIColor redColor]]; outputs @"l:#FF0000 d:#FF0000" +// ++ (NSString *)cscp_dynamicHexStringFromColor: (UIColor *)color; + +// +// returns a NSString representation of a UIColor in hex format eg [UIColor cscp_dynamicHexStringFromColor:[UIColor redColor] alpha:YES]; outputs @"#l:FFFF0000 d:FFFF0000" +// ++ (NSString *)cscp_dynamicHexStringFromColor: (UIColor *)color alpha:(BOOL)include; + // // returns a NSString representation of a UIColor in hex format eg [UIColor cscp_hexStringFromColor:[UIColor redColor]]; outputs @"#FF0000" // @@ -75,6 +85,16 @@ // - (CGFloat)cscp_brightness; +// +// the dynamic hexString value of the color instance +// +- (NSString *)cscp_dynamicHexString; + +// +// the dynamic hexString value of the color instance with alpha included +// +- (NSString *)cscp_dynamicHexStringWithAlpha; + // // the hexString value of the color instance // diff --git a/source/Categories/UIColor+CSColorPicker.m b/source/Categories/UIColor+CSColorPicker.m index fff758c..894b339 100644 --- a/source/Categories/UIColor+CSColorPicker.m +++ b/source/Categories/UIColor+CSColorPicker.m @@ -13,7 +13,45 @@ + (CGFloat)_cscp_colorComponentFrom:(NSString *)string start:(NSUInteger)start l @implementation UIColor (CSColorPicker) -+ (UIColor *)cscp_colorFromHexString:(NSString *)hexString { ++ (UIColor *)cscp_dynamicColorFromHexString:(NSString *)hexString { + + if (!hexString || !hexString.length) return [UIColor redColor]; + + if (![hexString containsString:@" "] || ![hexString.lowercaseString containsString:@"l:"] || ![hexString.lowercaseString containsString:@"d:"]) { + return [self _cscp_colorFromHexString:hexString]; + } + + NSArray *components = [hexString componentsSeparatedByString:@" "]; + + if (!components || !components.count) { + return [self _cscp_colorFromHexString:hexString]; + } + + UIColor *light = [self _cscp_colorFromHexString:[components.firstObject substringFromIndex:2]]; + + if (@available(iOS 13.0, *)) { + UIColor *dark = [self _cscp_colorFromHexString:[components.lastObject substringFromIndex:2]]; + return [UIColor colorWithDynamicProvider:^UIColor * (UITraitCollection *traitCollection) { + switch (traitCollection.userInterfaceStyle) { + case UIUserInterfaceStyleUnspecified: + case UIUserInterfaceStyleLight: + return light; + case UIUserInterfaceStyleDark: + return dark; + } + return light; + }]; + } + + return light; + +} + ++ (UIColor *)cscp_colorFromHexString:(NSString *)hexString { + return [self _cscp_colorFromHexString:hexString]; +} + ++ (UIColor *)_cscp_colorFromHexString:(NSString *)hexString { NSString *colorString = [[hexString stringByReplacingOccurrencesOfString:@"#" withString:@""] uppercaseString]; CGFloat alpha, red, blue, green; @@ -74,6 +112,40 @@ + (BOOL)cscp_isValidHexString:(NSString *)hexString { return (NSNotFound == [[[hexString stringByReplacingOccurrencesOfString:@"#" withString:@""] uppercaseString] rangeOfCharacterFromSet:hexChars].location); } ++ (NSString *)cscp_dynamicHexStringFromColor: (UIColor *)color { + return [self cscp_dynamicHexStringFromColor:color alpha:NO]; +} + ++ (NSString *)cscp_dynamicHexStringFromColor: (UIColor *)color alpha:(BOOL)include { + + CGFloat rl,gl,bl,al,rd,gd,bd,ad; + BOOL (^componentsForColor)(UIColor*, CGFloat*, CGFloat*, CGFloat*, CGFloat*) = ^BOOL (UIColor*color ,CGFloat*red, CGFloat*green, CGFloat*blue, CGFloat*alpha) { + BOOL value = [color getRed:red green:green blue:blue alpha:alpha]; + *red = roundf((float) (*red * 255.0f)); + *green = roundf((float) (*green * 255.0f)); + *blue = roundf((float) (*blue * 255.0f)); + *alpha = roundf((float) (*blue * 255.0f)); + return value; + }; + + if (@available(iOS 13.0, *)) { + componentsForColor( + [color resolvedColorWithTraitCollection:[UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleLight]], + &rl, &gl, &bl, &al + ); + componentsForColor( + [color resolvedColorWithTraitCollection:[UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark]], + &rd, &gd, &bd, &ad + ); + } else { + componentsForColor(color, &rl, &gl, &bl, &al); + componentsForColor(color, &rd, &gd, &bd, &ad); + } + + return include ? [[NSString stringWithFormat:@"l:%02x%02x%02x%02x d:%02x%02x%02x%02x", (int)al, (int)rl, (int)gl, (int)bl, (int)ad, (int)rd, (int)gd, (int)bd] uppercaseString] : + [[NSString stringWithFormat:@"l:%02x%02x%02x d:%02x%02x%02x", (int)rl, (int)gl, (int)bl, (int)rd, (int)gd, (int)bd] uppercaseString]; +} + + (NSString *)cscp_hexStringFromColor:(UIColor *)color { CGFloat red, green, blue; @@ -151,6 +223,14 @@ - (CGFloat)cscp_brightness { return b; } +- (NSString *)cscp_dynamicHexString { + return [UIColor cscp_dynamicHexStringFromColor:self]; +} + +- (NSString *)cscp_dynamicHexStringWithAlpha { + return [UIColor cscp_dynamicHexStringFromColor:self alpha:YES]; +} + - (NSString *)cscp_hexString { return [UIColor cscp_hexStringFromColor:self]; } diff --git a/source/Cells/CSBaseDisplayCell.h b/source/Cells/CSBaseDisplayCell.h new file mode 100644 index 0000000..d19a73b --- /dev/null +++ b/source/Cells/CSBaseDisplayCell.h @@ -0,0 +1,21 @@ +// +// Created by CreatureSurvive on 3/17/17. +// Copyright (c) 2016 - 2019 CreatureCoding. All rights reserved. +// + +#import +#import +#import +#import + + +@interface CSBaseDisplayCell : PSTableCell + +@property (nonatomic, retain) UIView *cellColorDisplay; + +- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)identifier specifier:(PSSpecifier *)specifier; +- (void)refreshCellContentsWithSpecifier:(PSSpecifier *)specifier; + +- (void)openColorPickerView; + +@end diff --git a/source/Cells/CSBaseDisplayCell.m b/source/Cells/CSBaseDisplayCell.m new file mode 100644 index 0000000..2da9149 --- /dev/null +++ b/source/Cells/CSBaseDisplayCell.m @@ -0,0 +1,81 @@ +// +// Created by CreatureSurvive on 3/17/17. +// Copyright (c) 2016 - 2019 CreatureCoding. All rights reserved. +// + +#import +#import + +@implementation CSBaseDisplayCell + +- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)identifier specifier:(PSSpecifier *)specifier { + + if ((self = [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier specifier:specifier])) { + [specifier setTarget:self]; + [specifier setButtonAction:@selector(openColorPickerView)]; + self.detailTextLabel.textColor = secondaryLabelColor(); + + self.cellColorDisplay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 58, 29)]; + self.cellColorDisplay.tag = 199; + self.cellColorDisplay.layer.cornerRadius = CGRectGetHeight(self.cellColorDisplay.frame) / 4; + self.cellColorDisplay.layer.borderWidth = 2; + self.cellColorDisplay.layer.borderColor = UIColor.lightGrayColor.CGColor; + [self setAccessoryView:self.cellColorDisplay]; + } + + return self; +} + +- (void)refreshCellContentsWithSpecifier:(PSSpecifier *)specifier { + [super refreshCellContentsWithSpecifier:specifier]; + +} + +- (void)openColorPickerView { + PSViewController *viewController; + UIViewController *vc; + + if ([self respondsToSelector:@selector(_viewControllerForAncestor)]) { + vc = [self performSelector:@selector(_viewControllerForAncestor)]; + } + + if (!vc) { + if ([self.specifier propertyForKey:@"parent"]) { + vc = [self.specifier propertyForKey:@"parent"]; + } else { + vc = UIViewParentController(self); + } + } + + if (vc && [vc isKindOfClass:[PSViewController class]]) { + viewController = (PSViewController *)vc; + } else { + return; + } + + + CSColorPickerViewController *colorViewController = [[CSColorPickerViewController alloc] init]; + + if (self.specifier && [self.specifier propertyForKey:@"defaults"] && [self.specifier propertyForKey:@"key"]) { + + colorViewController.specifier = self.specifier; + } + + colorViewController.view.frame = viewController.view.frame; + colorViewController.parentController = viewController; + colorViewController.specifier = self.specifier; + + if (firmwareGreaterThanEqual(@"13.0")) { + NSLog(@"%@", viewController.debugDescription); + [viewController presentViewController:NAVIGATION_WRAPPER_WITH_CONTROLLER(colorViewController) animated:YES completion:nil]; + } else { + [viewController.navigationController pushViewController:colorViewController animated:YES]; + } +} + +- (PSSpecifier *)specifier { + + return [super specifier]; +} + +@end diff --git a/source/Cells/CSColorDisplayCell.h b/source/Cells/CSColorDisplayCell.h index d3f68ac..4eb7ee1 100644 --- a/source/Cells/CSColorDisplayCell.h +++ b/source/Cells/CSColorDisplayCell.h @@ -3,20 +3,11 @@ // Copyright (c) 2016 - 2019 CreatureCoding. All rights reserved. // -#import -#import -#import -#import +#import -@interface CSColorDisplayCell : PSTableCell +@interface CSColorDisplayCell : CSBaseDisplayCell -@property (nonatomic, retain) UIView *cellColorDisplay; -@property (nonatomic, retain) NSMutableDictionary *options; - -- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)identifier specifier:(PSSpecifier *)specifier; - (void)refreshCellWithColor:(UIColor *)color; -- (void)openColorPickerView; - @end diff --git a/source/Cells/CSColorDisplayCell.m b/source/Cells/CSColorDisplayCell.m index c23bc03..8413910 100644 --- a/source/Cells/CSColorDisplayCell.m +++ b/source/Cells/CSColorDisplayCell.m @@ -7,18 +7,6 @@ #import @implementation CSColorDisplayCell -@synthesize cellColorDisplay; - -- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)identifier specifier:(PSSpecifier *)specifier { - - if ((self = [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier specifier:specifier])) { - [specifier setTarget:self]; - [specifier setButtonAction:@selector(openColorPickerView)]; - self.detailTextLabel.textColor = UIColor.lightGrayColor; - } - - return self; -} - (void)refreshCellContentsWithSpecifier:(PSSpecifier *)specifier { [super refreshCellContentsWithSpecifier:specifier]; @@ -40,64 +28,13 @@ - (void)refreshCellWithColor:(UIColor *)color { } - (void)didMoveToSuperview { - if (!self.specifier) { - return; - } - [super didMoveToSuperview]; - [self configureColorDisplay]; - [self refreshCellWithColor:nil]; -} - -- (void)configureColorDisplay { - self.cellColorDisplay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 58, 29)]; - self.cellColorDisplay.tag = 199; - self.cellColorDisplay.layer.cornerRadius = CGRectGetHeight(self.cellColorDisplay.frame) / 4; - self.cellColorDisplay.layer.borderWidth = 2; - self.cellColorDisplay.layer.borderColor = [UIColor lightGrayColor].CGColor; - [self setAccessoryView:self.cellColorDisplay]; -} - -- (void)openColorPickerView { - PSViewController *viewController; - UIViewController *vc; - - if ([self respondsToSelector:@selector(_viewControllerForAncestor)]) { - vc = [self performSelector:@selector(_viewControllerForAncestor)]; - } - - if (!vc) { - if ([self.specifier propertyForKey:@"parent"]) { - vc = [self.specifier propertyForKey:@"parent"]; - } else { - vc = UIViewParentController(self); - } - } - - if (vc && [vc isKindOfClass:[PSViewController class]]) { - viewController = (PSViewController *)vc; - } else { + if (!self.specifier) { return; } - - CSColorPickerViewController *colorViewController = [[CSColorPickerViewController alloc] init]; - - if (self.specifier && [self.specifier propertyForKey:@"defaults"] && [self.specifier propertyForKey:@"key"]) { - - colorViewController.specifier = self.specifier; - } - - colorViewController.view.frame = viewController.view.frame; - colorViewController.parentController = viewController; - colorViewController.specifier = self.specifier; - - if (firmwareGreaterThanEqual(@"13.0")) { - [viewController presentViewController:NAVIGATION_WRAPPER_WITH_CONTROLLER(colorViewController) animated:YES completion:nil]; - } else { - [viewController.navigationController pushViewController:colorViewController animated:YES]; - } + [self refreshCellWithColor:nil]; } - (UIColor *)previewColor { @@ -132,9 +69,4 @@ - (UIColor *)previewColor { return color; } -- (PSSpecifier *)specifier { - - return [super specifier]; -} - @end diff --git a/source/Cells/CSGradientDisplayCell.h b/source/Cells/CSGradientDisplayCell.h index 00c5cae..148ee70 100644 --- a/source/Cells/CSGradientDisplayCell.h +++ b/source/Cells/CSGradientDisplayCell.h @@ -3,21 +3,13 @@ // Copyright (c) 2016 - 2019 CreatureCoding. All rights reserved. // -#import -#import -#import -#import +#import -@interface CSGradientDisplayCell : PSTableCell +@interface CSGradientDisplayCell : CSBaseDisplayCell -@property (nonatomic, retain) UIView *cellColorDisplay; @property (nonatomic, retain) CAGradientLayer *gradient; -@property (nonatomic, retain) NSMutableDictionary *options; -- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)identifier specifier:(PSSpecifier *)specifier; - (void)refreshCellWithColors:(NSArray *)newColors; -- (void)openColorPickerView; - @end diff --git a/source/Cells/CSGradientDisplayCell.m b/source/Cells/CSGradientDisplayCell.m index 54004ba..6b864e5 100644 --- a/source/Cells/CSGradientDisplayCell.m +++ b/source/Cells/CSGradientDisplayCell.m @@ -7,15 +7,19 @@ #import @implementation CSGradientDisplayCell -@synthesize cellColorDisplay, gradient; - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)identifier specifier:(PSSpecifier *)specifier { if ((self = [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier specifier:specifier])) { - [specifier setTarget:self]; - [specifier setButtonAction:@selector(openColorPickerView)]; [specifier setProperty:@(YES) forKey:@"gradient"]; - self.detailTextLabel.textColor = UIColor.lightGrayColor; + + self.gradient = [CAGradientLayer layer]; + self.gradient.frame = self.cellColorDisplay.bounds; + self.gradient.cornerRadius = self.cellColorDisplay.layer.cornerRadius; + self.gradient.startPoint = CGPointMake(0, 0.5); + self.gradient.endPoint = CGPointMake(1, 0.5); + + [self.cellColorDisplay.layer addSublayer:self.gradient]; } return self; @@ -54,72 +58,13 @@ - (void)refreshCellWithColors:(NSArray *)newColors { } - (void)didMoveToSuperview { - if (!self.specifier) { - return; - } - [super didMoveToSuperview]; - - [self configureColorDisplay]; - [self refreshCellWithColors:nil]; -} - -- (void)configureColorDisplay { - self.cellColorDisplay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 58, 29)]; - self.cellColorDisplay.tag = 199; - self.cellColorDisplay.layer.cornerRadius = CGRectGetHeight(self.cellColorDisplay.frame) / 4; - self.cellColorDisplay.layer.borderWidth = 2; - self.cellColorDisplay.layer.borderColor = [UIColor lightGrayColor].CGColor; - - self.gradient = [CAGradientLayer layer]; - self.gradient.frame = self.cellColorDisplay.bounds; - self.gradient.cornerRadius = self.cellColorDisplay.layer.cornerRadius; - self.gradient.startPoint = CGPointMake(0, 0.5); - self.gradient.endPoint = CGPointMake(1, 0.5); - [self.cellColorDisplay.layer addSublayer:self.gradient]; - [self setAccessoryView:self.cellColorDisplay]; -} - -- (void)openColorPickerView { - PSViewController *viewController; - UIViewController *vc; - - if ([self respondsToSelector:@selector(_viewControllerForAncestor)]) { - vc = [self performSelector:@selector(_viewControllerForAncestor)]; - } - - if (!vc) { - if ([self.specifier propertyForKey:@"parent"]) { - vc = [self.specifier propertyForKey:@"parent"]; - } else { - vc = UIViewParentController(self); - } - } - - if (vc && [vc isKindOfClass:[PSViewController class]]) { - viewController = (PSViewController *)vc; - } else { + if (!self.specifier) { return; } - - CSColorPickerViewController *colorViewController = [[CSColorPickerViewController alloc] init]; - - if (self.specifier && [self.specifier propertyForKey:@"defaults"] && [self.specifier propertyForKey:@"key"]) { - - colorViewController.specifier = self.specifier; - } - - colorViewController.view.frame = viewController.view.frame; - colorViewController.parentController = viewController; - colorViewController.specifier = self.specifier; - - if (firmwareGreaterThanEqual(@"13.0")) { - [viewController presentViewController:NAVIGATION_WRAPPER_WITH_CONTROLLER(colorViewController) animated:YES completion:nil]; - } else { - [viewController.navigationController pushViewController:colorViewController animated:YES]; - } + [self refreshCellWithColors:nil]; } - (NSArray *)previewColors { @@ -154,9 +99,4 @@ - (void)openColorPickerView { return colors; } -- (PSSpecifier *)specifier { - - return [super specifier]; -} - @end diff --git a/source/Controllers/CSColorPickerViewController.h b/source/Controllers/CSColorPickerViewController.h index 9c57a43..0e12ec5 100644 --- a/source/Controllers/CSColorPickerViewController.h +++ b/source/Controllers/CSColorPickerViewController.h @@ -6,8 +6,6 @@ #import #import #import -#import -#import #import #import #import diff --git a/source/Controllers/CSColorPickerViewController.m b/source/Controllers/CSColorPickerViewController.m index 38bf475..41ecb7c 100644 --- a/source/Controllers/CSColorPickerViewController.m +++ b/source/Controllers/CSColorPickerViewController.m @@ -4,6 +4,8 @@ // #import +#import +#import #import #define SLIDER_HEIGHT 40.0 diff --git a/source/Controls/CSColorSlider.m b/source/Controls/CSColorSlider.m index 1c25421..fe936b7 100644 --- a/source/Controls/CSColorSlider.m +++ b/source/Controls/CSColorSlider.m @@ -89,8 +89,8 @@ - (void)baseInitWithType:(CSColorSliderType)sliderType label:(NSString *)label s [self setColor:startColor]; // fix eclipse coloring tracks - UIImageView *minTrack = [self performSelector:@selector(safeValueForKey:) withObject:@"_minTrackView"]; - UIImageView *maxTrack = [self performSelector:@selector(safeValueForKey:) withObject:@"_maxTrackView"]; + UIImageView *minTrack = [self respondsToSelector:@selector(_minTrackView)] ? [self performSelector:@selector(_minTrackView)] : nil; + UIImageView *maxTrack = [self respondsToSelector:@selector(_maxTrackView)] ? [self performSelector:@selector(_maxTrackView)] : nil; if (minTrack) { minTrack.hidden = YES; minTrack.tag = 199; diff --git a/source/Prefix.h b/source/Prefix.h index 08155e1..d409968 100644 --- a/source/Prefix.h +++ b/source/Prefix.h @@ -38,4 +38,13 @@ NS_INLINE BOOL firmwareEqual(NSString *version) { NS_INLINE __unused UINavigationController *NAVIGATION_WRAPPER_WITH_CONTROLLER(UIViewController *controller) { UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller]; return navigationController; +} + +NS_INLINE __unused UIColor *secondaryLabelColor() { + + if (@available(iOS 13, *)) { + return [UIColor secondaryLabelColor]; + } + + return [UIColor lightGrayColor]; } \ No newline at end of file