I have a simple AppDelegate like this:
class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
@IBOutlet weak var window: NSWindow!
@IBOutlet weak var field: NSView!
let button = NSButton()
let buttons = [NSButton(), NSButton(), NSButton()]
func applicationDidFinishLaunching(aNotification: NSNotification) {
button.frame = NSMakeRect(30, 60, 80, 25)
button.title = "ok"
field.addSubview(button)
for index in 0...2 {
let buttonI = buttons[index]
buttonI.frame = NSMakeRect(30+CGFloat(index)*90, 30, 80, 25)
buttonI.title = "not ok:\(index)"
field.addSubview(buttonI)
}
}
}
(You can test the above by connecting field
with a custom view inside the content view of the window).
When I run this I get the following button appearance:
Why is it that the single button looks ok while those from the array are not?
You just need to set the bezelStyle:
button.bezelStyle = .RoundedBezelStyle
buttonI.bezelStyle = .RoundedBezelStyle