NSButton on NSVisualEffectView: Wrong Background Color

最后都变了- 提交于 2019-12-12 07:37:32

问题


I have a NSVisualEffectView within a NSPopover developed for 10.10.

When subclassing the NSVisualEffectView to have hover background color effect, the borderless button color seems to be different

I tried setting the backgroundColor of the button cell to clearColor or the same as I used in drawRect: in of the NSVisualEffectView, the former gives wrong color (not filled with blue) and the later still the same with wrong color. (gray box around its border).

CALayer can fix this but is there a way without using it?

Any ideas?


回答1:


After much trial and error, this worked for me:

button.wantsLayer = true
button.layer?.backgroundColor = NSColor.clearColor().CGColor

I've got an NSTableView with NSVisualEffectView style. I created a custom NSTableViewCell class and put these lines in its drawRect method.



来源:https://stackoverflow.com/questions/30659384/nsbutton-on-nsvisualeffectview-wrong-background-color

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