Search code examples
swiftnsbutton

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.


Solution

  • Just set the bezelStyle of your NSButton to SmallSquareBezelStyle.

    newBut.bezelStyle = NSBezelStyle.SmallSquareBezelStyle