This repository was archived by the owner on Dec 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathPFColorCell.mm
executable file
·73 lines (56 loc) · 2.37 KB
/
PFColorCell.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#import "PSTableCell.h"
#import "PSSpecifier.h"
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
#import "ColorPicker.h"
@interface PFColorCell : PSTableCell
@end
@implementation PFColorCell
- (SEL)action {
return @selector(openColorPicker);
}
- (id)target {
return self;
}
- (SEL)cellAction {
return @selector(openColorPicker);
}
- (id)cellTarget {
return self;
}
- (void)openColorPicker {
UIViewController *viewController = [self _viewControllerForAncestor];
PFColorViewController *colorViewController = [[PFColorViewController alloc] initForContentSize:viewController.view.frame.size];
if (_specifier) {
NSDictionary *properties = _specifier.properties;
if (properties[@"color_key"] && properties[@"color_defaults"]) {
colorViewController.key = properties[@"color_key"];
colorViewController.defaults = properties[@"color_defaults"];
if (properties[@"usesAlpha"])
colorViewController.usesAlpha = [properties[@"usesAlpha"] boolValue];
if (properties[@"usesRGB"])
colorViewController.usesRGB = [properties[@"usesRGB"] boolValue];
colorViewController.title = properties[@"title"] ?: @"Choose Color";
colorViewController.fallback = properties[@"color_fallback"] ?: @"#a1a1a1";
colorViewController.postNotification = properties[@"color_postNotification"];
}
}
colorViewController.view.frame = viewController.view.frame;
[viewController.navigationController pushViewController:colorViewController animated:YES];
}
- (void)didMoveToSuperview {
[super didMoveToSuperview];
UIView *colorPreview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 29, 29)];
colorPreview.tag = 199; //Stop UIColors from overriding the color :P
colorPreview.layer.cornerRadius = colorPreview.frame.size.width / 2;
colorPreview.layer.borderWidth = 2;
colorPreview.layer.borderColor = [UIColor lightGrayColor].CGColor;
NSString *fallback = _specifier.properties[@"color_fallback"];
if (!fallback)
fallback = @"#a1a1a1";
colorPreview.backgroundColor = colorFromDefaultsWithKey([_specifier properties][@"color_defaults"], [_specifier properties][@"color_key"], fallback);
[self setAccessoryView:colorPreview];
[_specifier setTarget:self];
[_specifier setButtonAction:@selector(openColorPicker)];
}
@end