blob: b14d36cffd7682dad335aa55408d896e561e1f3a (
plain)
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
|
#import "MGLAttributionButton.h"
@implementation MGLAttributionButton {
NSTrackingRectTag _trackingAreaTag;
}
- (instancetype)initWithTitle:(NSString *)title URL:(NSURL *)url {
if (self = [super initWithFrame:NSZeroRect]) {
self.bordered = NO;
self.bezelStyle = NSRegularSquareBezelStyle;
// Start with a copyright symbol. The whole string will be mini.
NSMutableAttributedString *attributedTitle = [[NSMutableAttributedString alloc] initWithString:@"© "
attributes:@{
NSFontAttributeName: [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSMiniControlSize]],
}];
// Append the specified title, underlining it like a hyperlink.
[attributedTitle appendAttributedString:
[[NSAttributedString alloc] initWithString:title
attributes:@{
NSFontAttributeName: [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSMiniControlSize]],
NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle),
}]];
self.attributedTitle = attributedTitle;
[self sizeToFit];
_URL = url;
self.toolTip = _URL.absoluteString;
self.target = self;
self.action = @selector(openURL:);
}
return self;
}
- (BOOL)wantsLayer {
return YES;
}
- (void)resetCursorRects {
// The whole button gets a pointing hand cursor, just like a hyperlink.
[self addCursorRect:self.bounds cursor:[NSCursor pointingHandCursor]];
}
- (IBAction)openURL:(__unused id)sender {
[[NSWorkspace sharedWorkspace] openURL:self.URL];
}
@end
|