NSImageView on NSVisualEffectView

牧云@^-^@ 提交于 2019-12-13 07:25:19

问题


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.


回答1:


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.

Set image's isTemplate property to true. It will change according to appearance of menu item.



来源:https://stackoverflow.com/questions/42748004/nsimageview-on-nsvisualeffectview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!