我正在尝试更改主视图的背景颜色:
import AppKit
import PlaygroundSupport
class ViewController : NSViewController {
override func loadView() {
let nibFile = NSNib.Name("MyView")
var topLevelObjects : NSArray?
Bundle.main.loadNibNamed(
nibFile, owner:nil, topLevelObjects: &topLevelObjects)
let views = (topLevelObjects as! Array<Any>).filter { $0 is NSView }
self.view = views[0] as! NSView
self.view.layer?.backgroundColor = NSColor.white.cgColor
}
}
PlaygroundPage.current.liveView = ViewController()
但是视图不会改变颜色:
“ Hello world”标签也来自哪里?
非常感谢您的帮助