带有圆角的NSVisualEffectView [英] NSVisualEffectView with rounded corners

查看:114
本文介绍了带有圆角的NSVisualEffectView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在OS X中显示带有圆角的NSVisualEffectView?

How display a NSVisualEffectView with with rounded corners in OS X?

添加我的NSVisualEffectView的代码:

My code to add my NSVisualEffectView:

let visualEffectView = NSVisualEffectView(frame: NSMakeRect(0, 0, 300, 300))
visualEffectView.material = NSVisualEffectMaterial.Dark
visualEffectView.blendingMode = NSVisualEffectBlendingMode.BehindWindow
self.addSubview(visualEffectView)

推荐答案

通过将 wantsLayer 设置为 true ,可以为 NSVisualEffectView 启用层支持的视图.code>,然后设置衬里层的 cornerRadius :

You can enable layer backed views for your NSVisualEffectView by setting wantsLayer to true and then set the cornerRadius of the backing layer:

    let visualEffectView = NSVisualEffectView(frame: NSMakeRect(0, 0, 300, 300))
    visualEffectView.material = NSVisualEffectMaterial.Dark
    visualEffectView.blendingMode = NSVisualEffectBlendingMode.BehindWindow
    visualEffectView.wantsLayer = true
    visualEffectView.layer?.cornerRadius = 15.0
    self.view.addSubview(visualEffectView)

这会产生带有漂亮圆角的效果视图:

This results in a effect view with nice rounded corners:

这篇关于带有圆角的NSVisualEffectView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆