Transparent background WKWebView (NSView)
I am building a Mac application using Swift. Therefor, I want to make a WKWebView transparent, so it shows the text of the loaded HTML, but the background of my underlaying NSWindow is visible.
webView.layer?.backgroundColor = NSColor.clearColor().CGColor;
which hadn’t any effect. WKWebView inherits from NSView, but I don’t know if this helps.
Another solution would be to insert a NSVisualEffectView as the background of the WebView, but I don’t know how to accomplish that, either!
- Purpose of CALayer?
- NSString boundingRectWithSize returning unnecessarily tall height
- Change NSTabViewController NSSegmentedControl
- How to terminate all threads reading from Pipe (NSPipe) related to Process (NSTask)?
- Vertically aligning text in an NSTextField using Swift
- Replacements for the depreciated NSNibLoading methods (loadNibFile:, loadNibNamed:, etc.)?
3 Solutions Collect From Internet About “Transparent background WKWebView (NSView)”
Code below works for me perfectly, also color is set to clearColor by default.
[wkWebView setValue:YES forKey:@"drawsTransparentBackground"];
Use this in macOS 10.12 and higher:
webView.setValue(false, forKey: "drawsBackground")
- How to access launchEnvironment and launchArguments set in XCUIApplication, running UI tests in XCode?
- Converting Swift Array to NSData for NSUserDefaults.StandardUserDefaults persistent storage
- Swift 1.2 optional external variable?
- reloadTable after animated row deletion
- sqlite database update when app version changes on Appstore in iPhone
- Geolocation is not working in iOS 8 simulator
- Firebase Database indexPath
- Adding dark mode to iOS app
- Confused about Swift Array Declarations
- Xcode could not find a valid private-key certificate pair for this profile in your keychain
- How do I create a packed data structure in Swift?
- Firebase Swift 3 get list of child in a array
- Resume AVPlayer video playback after app become active
- How can i add a 2dView having text in ARkit scene iOS
- AVPlayer streaming progress