Skip to content

Instantly share code, notes, and snippets.

@eonist
Created January 27, 2016 14:09
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eonist/0c3cb90b5ad9ebcea83a to your computer and use it in GitHub Desktop.
Save eonist/0c3cb90b5ad9ebcea83a to your computer and use it in GitHub Desktop.
Translucent NSWindow Example
class TranslucentWin:NSWindow, NSApplicationDelegate, NSWindowDelegate{
/**
*
*/
override init(contentRect: NSRect, styleMask aStyle: Int, backing bufferingType: NSBackingStoreType, `defer` flag: Bool) {
super.init(contentRect: Win.sizeRect, styleMask: NSTitledWindowMask|NSResizableWindowMask|NSMiniaturizableWindowMask|NSClosableWindowMask|NSFullSizeContentViewWindowMask, backing: NSBackingStoreType.Buffered, `defer`: false)
self.contentView!.wantsLayer = true;/*this can and is set in the view*/
self.backgroundColor = NSColor.greenColor().alpha(0.2)
self.opaque = false
self.makeKeyAndOrderFront(nil)//moves the window to the front
self.makeMainWindow()//makes it the apps main menu?
//self.appearance = NSAppearance(named: NSAppearanceNameVibrantDark)
self.titlebarAppearsTransparent = true
self.center()
//self.contentView = view
//self.title = ""/*Sets the title of the window*/
self.title = ""//GitSync
self.delegate = self
let visualEffectView = NSVisualEffectView(frame: NSMakeRect(0, 0, Win.sizeRect.width, Win.sizeRect.height))
visualEffectView.material = NSVisualEffectMaterial.AppearanceBased//Dark,MediumLight,PopOver,UltraDark,AppearanceBased,Titlebar,Menu
visualEffectView.blendingMode = NSVisualEffectBlendingMode.BehindWindow
visualEffectView.state = NSVisualEffectState.Active
self.contentView?.addSubview(visualEffectView)
//self.contentView = visualEffectView
/* self.contentView!.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[visualEffectView]-0-|", options: NSLayoutFormatOptions.DirectionLeadingToTrailing, metrics: nil, views: ["visualEffectView":visualEffectView]))
self.contentView!.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[visualEffectView]-0-|", options: NSLayoutFormatOptions.DirectionLeadingToTrailing, metrics: nil, views: ["visualEffectView":visualEffectView]))
*/
//visualEffectView.wantsLayer = true;//this should be set in the iew not here
//visualEffectView.allowsVibrancy.interiorBackgroundStyle // only radable
//visualEffectView.allowsVibrancy = true
//visualEffectView.blendingMode = NSVisualEffectBlendingModeWithinWindow,
}
required init?(coder: NSCoder) {fatalError("init(coder:) has not been implemented")}/*Required by the NSWindow*/
}
@eonist
Copy link
Author

eonist commented Jan 29, 2016

Example:

screen shot 2016-01-24 at 07 46 17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment