How To Make Part of Web View Slightly Translucent?

前端 未结 2 1275
遇见更好的自我
遇见更好的自我 2020-12-22 08:24

In Objective-C with Mac OSX Cocoa, is there any way to make a DIV on a WebView slightly translucent so that

相关标签:
2条回答
  • 2020-12-22 09:12

    Related Step by step Tutorial with examples:

    http://stylekit.org/blog/2016/01/23/Chromeless-window/

    Setting up translucency:

    1. Set the styleMask of your NSWindow subclass to NSFullSizeContentViewWindowMask (so that the translucency will also be visible in the titlebar area, leave this out and the titlebar area will be blank)
    2. Set the self.titlebarAppearsTransparent = true (hides the titlebar default graphics)
    3. Add the code bellow to your NSWindow subclass: (you should now have a translucent window)

    .

    let visualEffectView = NSVisualEffectView(frame: NSMakeRect(0, 0, 0, 0))//<---the width and height is set to 0, as this doesn't matter. 
    visualEffectView.material = NSVisualEffectMaterial.AppearanceBased//Dark,MediumLight,PopOver,UltraDark,AppearanceBased,Titlebar,Menu
    visualEffectView.blendingMode = NSVisualEffectBlendingMode.BehindWindow//I think if you set this to WithinWindow you get the effect safari has in its TitleBar. It should have an Opaque background behind it or else it will not work well
    visualEffectView.state = NSVisualEffectState.Active//FollowsWindowActiveState,Inactive
    self.contentView = visualEffectView/*you can also add the visualEffectView to the contentview, just add some width and height to the visualEffectView, you also need to flip the view if you like to work from TopLeft, do this through subclassing*/
    

    0 讨论(0)
  • 2020-12-22 09:20

    Yes, just set the drawsBackground property of your WebView instance to NO, then make sure to fill the parts of the page you want opaque using CSS.

    0 讨论(0)
提交回复
热议问题