Given the code below:
let alert = NSAlert()
alert.alertStyle = .informational
alert.messageText = "Foo"
alert.informativeText = "Bar"
alert.addButton(withTitle: "Foo").keyEquivalent = "\r"
alert.addButton(withTitle: "Bar")
alert.addButton(withTitle: "Cancel").keyEquivalent = "\u{1b}" // esc
alert.runModal()
The resulting alert looks like one would expect:
However, add another button:
let alert = NSAlert()
alert.alertStyle = .informational
alert.messageText = "Foo"
alert.informativeText = "Bar"
alert.addButton(withTitle: "Foo").keyEquivalent = "\r"
alert.addButton(withTitle: "Bar")
alert.addButton(withTitle: "Baz")
alert.addButton(withTitle: "Cancel").keyEquivalent = "\u{1b}" // esc
alert.runModal()
And suddenly you get this:
As you can see, the "Bar" and "Baz" buttons no longer get drawn (except when the mouse hovers over them), even though the "Bar" button draws perfectly normally when it's the only middle button.
I Have Questions:
-
Is this behavior intentional, or some kind of glitch? The pictures in the macOS HI Guidelines still seem to be showing the Yosemite-era layout, making it difficult to determine what these alerts are supposed to look like.
-
If this is a glitch, is there a better way to work around it than messing with the
NSButton
display properties directly? -
If this is intentional... why? It's so weird looking...