-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathULIFontPickerButton.m
73 lines (53 loc) · 1.32 KB
/
ULIFontPickerButton.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
//
// ULIFontPickerButton.m
// Stacksmith
//
// Created by Uli Kusterer on 01/05/16.
// Copyright © 2016 Uli Kusterer. All rights reserved.
//
#import "ULIFontPickerButton.h"
#if !__has_feature(objc_arc)
#error This file requires ARC. Please add the -fobjc-arc compiler option for this file.
#endif
@implementation ULIFontPickerButton
-(BOOL) canBecomeKeyView
{
return YES;
}
-(BOOL) acceptsFirstResponder
{
return YES;
}
-(BOOL) becomeFirstResponder
{
[self setState: NSOnState];
[[NSFontPanel sharedFontPanel] setPanelFont: self.pickedFont isMultiple: NO];
return YES;
}
-(BOOL) resignFirstResponder
{
NSLog(@"resignFirstResponder");
[self setState: NSOffState];
return YES;
}
-(void) changeFont: (nullable id)sender
{
NSFont* theFont = self.pickedFont;
NSFont * newFont = [[NSFontPanel sharedFontPanel] panelConvertFont: theFont];
if( newFont )
theFont = newFont;
self.pickedFont = theFont;
}
-(void) setPickedFont: (NSFont *)pickedFont
{
_pickedFont = pickedFont;
self.title = [NSString stringWithFormat: @"%@ – %.1f", _pickedFont.fontName, _pickedFont.pointSize];
[super sendAction: self.action to: self.target];
}
-(BOOL) sendAction: (SEL)theAction to: (nullable id)theTarget
{
[self.window makeFirstResponder: self];
[[NSFontPanel sharedFontPanel] orderFront: self];
return YES;
}
@end