-
Notifications
You must be signed in to change notification settings - Fork 3
/
IPDFMacColorPanel.m
76 lines (57 loc) · 1.65 KB
/
IPDFMacColorPanel.m
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
74
75
76
//
// IPDFMacColorPanel.m
// InstaPDF for Mac
//
// Created by mmackh on 15.10.19.
// Copyright © 2019 mackh ag. All rights reserved.
//
#import "IPDFMacColorPanel.h"
@interface NSColorPanel_Catalyst : NSObject
+ (instancetype)sharedColorPanel;
- (void)makeKeyAndOrderFront:(id)sender;
- (void)orderFront:(id)sender;
- (void)orderOut:(id)sender;
- (void)setTarget:(id)target;
- (void)setAction:(SEL)action;
- (UIColor *)color;
@end
@interface IPDFMacColorPanel ()
@property (nonatomic,copy) void(^colorChangeHandler)(UIColor *color);
@end
@implementation IPDFMacColorPanel
+ (instancetype)sharedPanel
{
static IPDFMacColorPanel *panel = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
panel = [IPDFMacColorPanel new];
});
return panel;
}
+ (NSColorPanel_Catalyst *)colorPanel
{
return [NSClassFromString(@"NSColorPanel") performSelector:@selector(sharedColorPanel)];
}
+ (void)showColorPanelWithColorChangeHandler:(void(^)(UIColor *color))colorChangeHandler
{
IPDFMacColorPanel *observer = [IPDFMacColorPanel sharedPanel];
observer.colorChangeHandler = colorChangeHandler;
NSColorPanel_Catalyst *colorPanel = [self colorPanel];
[colorPanel setTarget:observer];
[colorPanel setAction:@selector(colorChange:)];
[colorPanel orderFront:nil];
}
+ (void)hide
{
[[self colorPanel] orderOut:nil];
[self removeColorChangeHandlerObserver];
}
+ (void)removeColorChangeHandlerObserver
{
[IPDFMacColorPanel sharedPanel].colorChangeHandler = nil;
}
- (void)colorChange:(NSColorPanel_Catalyst *)colorPanel
{
if (self.colorChangeHandler) self.colorChangeHandler(colorPanel.color);
}
@end