在 NSView 上使用自定义阴影路径

问题描述 投票:0回答:0

不幸的是,直接在图层上设置阴影属性似乎不起作用:

let shadowView = NSView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
shadowView.wantsLayer = true
shadowView.layer!.backgroundColor = .white
shadowView.layer!.shadowRadius = 50
shadowView.layer!.shadowColor = .black
shadowView.layer!.shadowOffset = CGSize(width: 0, height: -30)
shadowView.layer!.shadowPath = CGPath(roundedRect: shadowView.bounds, cornerWidth: 25, cornerHeight: 25, transform: nil)

改为设置 NSView.shadow 属性:

let shadowView = NSView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))let shadow = NSShadow()
shadow.shadowBlurRadius = 50
shadow.shadowColor = .black
shadow.shadowOffset = CGSize(width: 0, height: -30)
shadowView.shadow = shadow
shadowView.wantsLayer = true
shadowView.layer!.backgroundColor = .white

但是

NSShadow
不支持自定义路径。使用自定义路径设置阴影的最简单方法是什么?

cocoa calayer nsview
© www.soinside.com 2019 - 2024. All rights reserved.