简体   繁体   中英

NSVisualEffectBlendingMode OS X Swift

I want to be able to make the background of my application blurry so you can almost see through the window like this

在此处输入图片说明

rather than the standard window

在此处输入图片说明

Thank you!

I Found out the answer I was looking for and thought this might be useful for other people look for something similar. Heres my code :

import Cocoa

class window: NSWindowController {

override func windowDidLoad() {
    super.windowDidLoad()

    let view = NSVisualEffectView(frame: NSRect(x: 0, y: 0, width: 1500, height: 800))
    view.blendingMode = NSVisualEffectBlendingMode.BehindWindow
    view.material = NSVisualEffectMaterial.Dark
    view.state = NSVisualEffectState.Active
    self.window!.contentView!.addSubview(view)

}

}

I made a NSWindowController class and added the code above to it. Then connected the class to the window controller in my main.storyboard.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM