如何在NSTexturedSquareBezelStyle按钮周围绘制边框

时间:2021-09-04 23:56:54

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.

经过一番挖掘,我了解到典型的按钮使用了NSRoundedBezelStyle,但它有一个固定的高度。因此,如果要包装文本,Firefox(以及Chrome和Safari)将更改按钮以使用可具有可变高度的NSShadowlessSquareBezelStyle。我想请求这些浏览器的维护者改变这一点,并且正在研究最佳替代方案。

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.

在找到已经提交的错误并进行一些阅读之后,我建议也许他们可以使用NSTexturedSquareBezelStyle代替。事实证明,在Mavericks中,它看起来与NSRoundedBezelStyle按钮几乎完全相同。同样在优胜美地,但它没有边界。更改setBordered无效。

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?

所以我的问题,代表各处的浏览器开发人员:是否可以绘制带边框的NSTexturedSquareBezelStyle按钮?或者,是否存在所有浏览器供应商错过的另一种方法?

1 个解决方案

#1


3  

Rewritten Answer

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

我没有在Yosemite看到NSTexturedSquareBezelStyle按钮显示无边框:

如何在NSTexturedSquareBezelStyle按钮周围绘制边框

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:

这是从Interface Builder中的调色板拖动的库存按钮。我鼓励您发布代码,因为您可能正在代码中生成按钮。这是我自己生成相同按钮的代码:

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

Proof:

如何在NSTexturedSquareBezelStyle按钮周围绘制边框

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.

如果您在Yosemite下看到不同的结果,则需要发布您的代码。猜测,您可能正在使用-init而不是-initWithFrame:来初始化您的按钮,这可能会导致各种绘图问题,因为NSButton是一个NSView,因此它的指定初始化程序是-initWithFrame:。只是一个猜测。

#1


3  

Rewritten Answer

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

我没有在Yosemite看到NSTexturedSquareBezelStyle按钮显示无边框:

如何在NSTexturedSquareBezelStyle按钮周围绘制边框

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:

这是从Interface Builder中的调色板拖动的库存按钮。我鼓励您发布代码,因为您可能正在代码中生成按钮。这是我自己生成相同按钮的代码:

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

Proof:

如何在NSTexturedSquareBezelStyle按钮周围绘制边框

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.

如果您在Yosemite下看到不同的结果,则需要发布您的代码。猜测,您可能正在使用-init而不是-initWithFrame:来初始化您的按钮,这可能会导致各种绘图问题,因为NSButton是一个NSView,因此它的指定初始化程序是-initWithFrame:。只是一个猜测。