【Swift Mac开发】开发日常小记录Tips

  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
        }
    }
}

 

上一篇:《100-gdb-tips》——查看调用堆栈


下一篇:[Tips] updraftplus备份wordpress