Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw a border around an NSTexturedSquareBezelStyle button

I noticed the other day that one of my web pages was looking ugly. The buttons on the page looked totally different, based on whether they contained one line of text or two.

After some digging, I've learned that the typical button uses NSRoundedBezelStyle, but it has a fixed height. So, if the text is going to wrap, Firefox (and Chrome and Safari) will change the button to use NSShadowlessSquareBezelStyle which can have a variable height. I'd like to petition the maintainers of these browsers to change this and am researching the best alternative.

After finding the already-filed bug and doing some reading, I suggested that maybe they could use NSTexturedSquareBezelStyle instead. It turns out that in Mavericks it looks almost exactly the same as an NSRoundedBezelStyle button. Same in Yosemite, except that it has no border. Changing setBordered has no effect.

So my question, on behalf of browser developers everywhere: is it possible to draw an NSTexturedSquareBezelStyle button with a border? Or, is there another way around this that all the browser vendors have missed?

like image 393
miken32 Avatar asked Apr 22 '15 19:04

miken32


1 Answers

Rewritten Answer

I'm not seeing an NSTexturedSquareBezelStyle button showing up borderless in Yosemite:

NSTexturedSquareButonStyle button under Yosemite.

This is a stock button dragged from the palette in Interface Builder. I encourage you to post your code since it's likely you're generating your button in code. Here's my own code for generating the same button:

NSButton * anotherButton = [[NSButton alloc] initWithFrame:NSMakeRect(10.0, 10.0, 100.0, 100.0)];
anotherButton.bezelStyle = NSTexturedSquareBezelStyle;
anotherButton.title = @"Line 1\nLine 2";

Proof:

Same button created with code.

If you're seeing different results under Yosemite, you'll need to post your code. At a guess, you might be initializing your button with -init instead of -initWithFrame:, which can cause all kinds of drawing issues since NSButton is an NSView and therefore its designated initializer is -initWithFrame:. Just a guess though.

like image 117
Joshua Nozzi Avatar answered Nov 11 '22 08:11

Joshua Nozzi