1、禁止NSViewController更改大小
override func viewDidAppear() { super.viewDidAppear() view.window!.styleMask.remove(.resizable) }
2、更改NSTextField的背景颜色
更改NSTextField的背景颜色与NSView的不同,不需要Wantslayer
textField.backgroundColor = NSColor.lightGray
3、设置NSImageView的填充样式
import Foundation import Cocoa class BMBaseImageView: NSImageView { override var image: NSImage? { set { self.layer = CALayer() //设置图片的填充样式 self.layer?.contentsGravity = CALayerContentsGravity.resizeAspectFill self.layer?.contents = newValue self.wantsLayer = true super.image = newValue } get { return super.image } } }