Hello,
I have a menu bar element in OS X 10.11 next to the system time.
It's showing the number of seconds since one event, that the user had choosen.
For example the number:
5.230.185
The problem is, that the width of the String changes every second, because of the different width of the numbers 0 to 9.
5.230.181 is thinner than
5.230.188
I want to know how to fix the width of the numbers, that you cannot see this difference. The system time in the menu also don't have this problem.
My title is for example:
statusItem.title = "5.230.181"
Could someone help me?
I have seen, that I can use statusItem.attributedTitle instead of statusItem.title.
Right.
But I don't know how to use it.
You’ll have to:
create a font for the monospaced system font of your preferred size
wrap your string in an attributed string that references that font
let font = NSFont.monospacedDigitSystemFontOfSize(12.0, weight: NSFontWeightRegular)
let attributedString = NSAttributedString(string: "foo", attributes: [NSFontAttributeName: font])
Again, I’ve not tried this for an NSStatusItem but I can’t see any reason why it wouldn’t work.
Share and Enjoy
—
Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"