Tuesday, October 10, 2023

Hacking NSAlert Button Appearance

Daniel Jalkut:

Notice how the “Bar” and “Baz” buttons do not have a border or background color, making it difficult to know whether they are even buttons at all. The line between Bar and Baz clunks up the interface even more.

[…]

This exploded view from the Xcode view debugger shows that the top, default button, is showing the background for the button, while the other buttons don’t have one at all.

[…]

So how would you work around such a problem? As I shared in the thread on the forums, one approach that seems both safe and effective is to patch up the appearance of the buttons, and hide the unwanted line. Because NSAlert performs a great number of modifications as it’s displaying the alert, you have to subclass and override its “layout()” method to catch it after it’s done tweaking the UI[…]

Pierre Igot:

After years of fine-tuning, all the kinks have finally been worked out.

Previously:

Comments RSS · Twitter · Mastodon

Leave a Comment