NSVisualEffectView上的NSImageView [英] NSImageView on NSVisualEffectView
问题描述
我需要使用右侧的图标制作NSMenuItem.我最终获得了自定义视图,该视图在NSVisualEffectView顶部包含NSTextField和NSImageView以及选择材料,这些材料用于模仿系统选择. NSVisualEffectView默认情况下是隐藏的. 但是,在选择项目时,我NSVisualEffectView出现在屏幕上绘制图像与背景.我该如何摆脱呢? wantLayer = YES和backgroundColor = CGColor.clear没有帮助. 预先感谢.
I need to make NSMenuItem with icon at the right side. I ended up with custom view which contains NSTextField and NSImageView on top of NSVisualEffectView with selection material, that I use to imitate system selection. NSVisualEffectView is hidden by default. But when the item is selected, my NSVisualEffectView appears on screen and image is drawn with background. How can I get rid of it? wantsLayer = YES and backgroundColor = CGColor.clear did not help. Thanks in advance.
推荐答案
您无需显式添加NSVisualEffectView.默认情况下,菜单项具有NSVisualEffectView作为superView.您可以使用该VisualEffectView模仿选择行为. 单击此处下载演示项目.
You don't need to add NSVisualEffectView explicitly. By default, menu items have NSVisualEffectView as superView. You can use that VisualEffectView to imitate the selection behavior. Click here to download a demo project.
将图像的isTemplate
属性设置为true.它会根据菜单项的外观而变化.
Set image's isTemplate
property to true. It will change according to appearance of menu item.
这篇关于NSVisualEffectView上的NSImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!