I want to create an osx/cocoa application on my mac, which does something very simple: Display a text string on my mac, with no background. Ultimately this will be a timer which displays as an overlay on top of other windows, without being too intrusive.
I tried setting window.backgroundColor = NSColor(red: 1.0, green:0.5, blue:0.5, alpha: 0.5)
(see the alpha is 0.5), in applicationDidFinishLaunching
but this doesn't turn it into something remotely transparent.
Any good soul wants to suggest a way to do this?
Make the desktop less transparent: Choose Apple menu > System Preferences, click Accessibility , click Display, click Display, then select “Reduce transparency.” The transparent areas of the desktop and app windows become gray.
xib, you simply do it in interface builder by selecting the option "Clear Color" for the Background of the view in the Utilities Pane (the pane on the right). "Clear Color" will give the view a completely transparent background.
Any SwiftUI view can be partially or wholly transparent using the opacity() modifier. This accepts a value between 0 (completely invisible) and 1 (fully opaque), just like the alpha property of UIView in UIKit.
Just add a Storyboard Segue with Kind set to Present Modally to your modal view controller and on this view controller set the following values: Background = Clear Color. Drawing = Uncheck the Opaque checkbox.
NSWindow has a property 'opaque' which it is true by default.
The value of this property is true when the window is opaque; otherwise, false.
Just change it to false:
override func viewWillAppear() {
super.viewWillAppear()
view.window?.opaque = false
view.window?.backgroundColor = NSColor(red: 1, green: 0.5, blue: 0.5, alpha: 0.5)
}
Swift 4 update: opaque
has been renamed isOpaque
override func viewWillAppear() {
super.viewWillAppear()
view.window?.isOpaque = false
view.window?.backgroundColor = NSColor(red: 1, green: 0.5, blue: 0.5, alpha: 0.5)
}
Make the window non-opaque, and give it a clear background:
func applicationDidFinishLaunching(aNotification: NSNotification) {
window.opaque = false
window.backgroundColor = NSColor.clearColor()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With