diff --git a/MTMR/CustomButtonTouchBarItem.swift b/MTMR/CustomButtonTouchBarItem.swift index b068ef1..b89f130 100644 --- a/MTMR/CustomButtonTouchBarItem.swift +++ b/MTMR/CustomButtonTouchBarItem.swift @@ -95,9 +95,6 @@ class CustomButtonCell: NSButtonCell { } else { self.isBordered = false } - - self.font = NSFont.systemFont(ofSize: 15, weight: .regular ) - } required init(coder: NSCoder) { @@ -105,3 +102,18 @@ class CustomButtonCell: NSButtonCell { } } +extension NSButton { + var title: String { + get { + return "" + } + + set (newTitle) { + let attrTitle = NSMutableAttributedString(string: newTitle as String, attributes: [NSAttributedStringKey.foregroundColor: NSColor.white, NSAttributedStringKey.font: NSFont.systemFont(ofSize: 15, weight: .regular)]) + attrTitle.setAlignment(.center, range: NSRange(location: 0, length: newTitle.count)) + + self.attributedTitle = attrTitle + } + } +} + diff --git a/MTMR/Widgets/CurrencyBarItem.swift b/MTMR/Widgets/CurrencyBarItem.swift index 7322499..f648db3 100644 --- a/MTMR/Widgets/CurrencyBarItem.swift +++ b/MTMR/Widgets/CurrencyBarItem.swift @@ -107,14 +107,10 @@ class CurrencyBarItem: CustomButtonTouchBarItem { } self.oldValue = value - button.title = String(format: "%@%.2f", self.prefix, value) - - let textRange = NSRange(location: 0, length: button.title.count) - let newTitle = NSMutableAttributedString(string: button.title) - newTitle.addAttribute(NSAttributedStringKey.foregroundColor, value: color, range: textRange) - newTitle.addAttribute(NSAttributedStringKey.font, value: button.font!, range: textRange) - newTitle.setAlignment(.center, range: textRange) + let title = String(format: "%@%.2f", self.prefix, value) + let newTitle = NSMutableAttributedString(string: title as String, attributes: [NSAttributedStringKey.foregroundColor: color, NSAttributedStringKey.font: NSFont.systemFont(ofSize: 15, weight: .regular)]) + newTitle.setAlignment(.center, range: NSRange(location: 0, length: title.count)) button.attributedTitle = newTitle } }