简体   繁体   English

以编程方式快速创建方形NSButton

[英]Create square NSButton programmatically swift

There's my code: 有我的代码:

var newBut = NSButton(frame: NSRect(x: 150, y: 200, width: 30, height: 30))
newBut.title = "press me!"
self.view.addSubview(newBut)

But it creates the button that differs from square button. 但它创建的按钮与方形按钮不同。 It's darker and has smh like a shadow. 它更暗,像阴影一样。 I'm looking for a way to change its appearance to copy the square button style. 我正在寻找一种方法来改变它的外观来复制方形按钮样式。

只需将NSButton的bezelStyle设置为bezelStyle SmallSquareBezelStyle

newBut.bezelStyle = NSBezelStyle.SmallSquareBezelStyle

In Swift 4 (Xcode 9) " bezelStyle " is now " BezelStyle ". Swift 4 (Xcode 9)中,“ bezelStyle ”现在是“ BezelStyle ”。

Note that, BezelStyle no longer has a member " SmallSquareBezelStyle ". 请注意, BezelStyle不再具有“ SmallSquareBezelStyle ”成员。 BezelStyle is a "UInt". BezelStyle是一个“UInt”。

Per Apple " NSButton.BezelStyle " documentation, BezelStyle can be: 根据Apple“ NSButton.BezelStyle ”文档,BezelStyle可以是:

  • circular
  • disclosure 泄露
  • helpButton helpButton
  • inLine 排队
  • recessed 凹进
  • regularSquare regularSquare
  • roundRect ROUNDRECT
  • rounded
  • roundedDisclosure roundedDisclosure
  • shadowlessSquare shadowlessSquare
  • smallSquare smallSquare
  • textureRounded, and textureRounded,和
  • texturedSquare texturedSquare

It seems that you were looking at one of the "square" button cases. 看来你正在看一个“方形”按钮的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM