From d300bdba4a8cdfaa6984dba4c3582e4e436cb49f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LIU=20Dongyuan=20/=20=E6=9F=B3=E4=B8=9C=E5=8E=9F?= Date: Tue, 3 Feb 2015 12:57:04 -0800 Subject: [PATCH] Remove some magic numbers. --- quark-shell/QSHStatusItemView.h | 2 ++ quark-shell/QSHStatusItemView.m | 2 +- quark-shell/QSHWebViewDelegate.m | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/quark-shell/QSHStatusItemView.h b/quark-shell/QSHStatusItemView.h index 04325e4..896589d 100644 --- a/quark-shell/QSHStatusItemView.h +++ b/quark-shell/QSHStatusItemView.h @@ -10,6 +10,8 @@ @interface QSHStatusItemView : NSButton +#define MENUBAR_FONT [NSFont menuBarFontOfSize:14.0] + @property (nonatomic, weak) NSStatusItem *statusItem; @property (nonatomic) BOOL itemHighlighted; // differentiate from NSControl’s highlighted @property (nonatomic) NSImage *icon; diff --git a/quark-shell/QSHStatusItemView.m b/quark-shell/QSHStatusItemView.m index 5d46715..6c9373a 100644 --- a/quark-shell/QSHStatusItemView.m +++ b/quark-shell/QSHStatusItemView.m @@ -60,7 +60,7 @@ iconFrame = NSMakeRect(3, yOffset, 20, 20); NSColor *color = self.itemHighlighted ? [NSColor whiteColor] : [NSColor blackColor]; NSDictionary *barTextAttributes = @{ - NSFontAttributeName: [NSFont systemFontOfSize:14.0], + NSFontAttributeName: MENUBAR_FONT, NSForegroundColorAttributeName: color }; [self.label drawInRect:NSMakeRect(25, 2, NSWidth(self.bounds) - 30, 20) withAttributes:barTextAttributes]; diff --git a/quark-shell/QSHWebViewDelegate.m b/quark-shell/QSHWebViewDelegate.m index 81c1d55..24b7f99 100644 --- a/quark-shell/QSHWebViewDelegate.m +++ b/quark-shell/QSHWebViewDelegate.m @@ -216,13 +216,15 @@ static const NSInteger kPreferencesDefaultHeight = 192; - (void)changeLabel:(NSString *)label { + NSDictionary *barTextAttributes; if (IS_PERIOR_TO_10_9) { self.statusItemView.label = label; + barTextAttributes = @{NSFontAttributeName: MENUBAR_FONT}; } else { self.statusItem.title = label; + barTextAttributes = @{NSFontAttributeName: self.statusItem.button.font}; } - NSDictionary *barTextAttributes = @{NSFontAttributeName: [NSFont systemFontOfSize:14.0]}; // 20 is image width, 10 is extra margin self.statusItem.length = 20 + [label sizeWithAttributes:barTextAttributes].width + 10; }