swift - 更改 NSVisualEffectView 的颜色
问题描述
我目前正在尝试更改 NSVisualEffectView 的色调。这是我到目前为止得到的:
class MainViewViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
// create a colored view to tint the visual effect view
let coloredView = NSView(frame: self.view.frame)
coloredView.layer?.backgroundColor = NSColor(red: 1, green: 0, blue: 0, alpha: 0.5).cgColor
// create the visual effect view for the background blur
let visualEffectView = NSVisualEffectView(frame: self.view.frame)
visualEffectView.addSubview(coloredView)
// add the visual effect view
self.view.addSubview(visualEffectView, positioned: NSWindow.OrderingMode.below, relativeTo: nil)
}
}
如您所见,我尝试添加另一个图层来为视觉效果视图着色。然而这并没有奏效。
有没有机会改变 NSVisualEffectView 的颜色?
解决方案
您不会更改视觉效果视图的“颜色”,因为它没有颜色。视觉效果视图根据视图的材质和混合模式混合背景和前景(子视图)。“背景”要么是窗口内视觉效果视图下的内容,要么是窗口后面的内容。
在这些示例中,在红色 NSBox 中的视觉效果视图中有一个蓝色 NSBox。
这个视觉效果视图的混合模式是“后”窗口。请注意,您可以从窗口后面看到绿色作为视觉效果视图中的混合背景。
此视觉效果视图的混合模式是“窗口内”。请注意,您会看到红色框,它是视觉效果视图的背景。
在这两种情况下,材料的外观都很“轻”。不同的材料会有不同的外观。
没有通用的方法可以让视觉效果视图创建“模糊的彩色背景”。它旨在根据材料/混合模式组合以特定方式使用,并且每种方式都有不同的外观。
推荐阅读
- mysql - 如何使用 JPA 向 MySQL 添加前缀索引?
- excel - 我忘记了将文本更改为 URL 格式的 Excel 公式
- html - 运行代码后有时宏无法设置 htmldiv
- angular - 如何仅允许数字指令角度 9 的复制粘贴
- powershell - powershell - 在文件中匹配后删除 n 行
- php - 在php中构建rest中间件的最佳方法
- ansible - blockinfile 模块中的 jinja 变量替换
- json - 将具有多个嵌套值的字段从 JSON 导出到 CSV
- python - 获取熊猫数据框中不同值的最有效方法是什么?
- opc-ua - 是否有任何开源 OPC UA 服务器,我可以在其中添加和配置 FileType 的节点