我有一个像这样简单的AppDelegate:
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)
}
}
}
(您可以通过在窗口的内容视图中将field
与自定义视图相关联来测试上述内容。)
当我运行时,我得到以下按钮外观:
为什么单个按钮看起来没问题而数组中的按钮看起来没有?
答案 0 :(得分:1)
您只需要设置bezelStyle:
button.bezelStyle = .RoundedBezelStyle
buttonI.bezelStyle = .RoundedBezelStyle