NSVisualEffectView 上的 NSButton:背景颜色错误 [英] NSButton on NSVisualEffectView: Wrong Background Color

查看:71
本文介绍了NSVisualEffectView 上的 NSButton:背景颜色错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在为 10.10 开发的 NSPopover 中有一个 NSVisualEffectView.

I have a NSVisualEffectView within a NSPopover developed for 10.10.

当子类化NSVisualEffectView有悬停背景颜色效果时,无边框按钮颜色似乎不同

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

我尝试将按钮单元的 backgroundColor 设置为 clearColor 或与我在 drawRect: 中使用的相同NSVisualEffectView,前者颜色错误(未填充蓝色),后者颜色错误还是一样.(边框周围的灰色框).

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 可以解决这个问题,但有没有不使用它的方法?

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

有什么想法吗?

推荐答案

经过多次尝试和错误,这对我有用:

After much trial and error, this worked for me:

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

我有一个 NSVisualEffectView 风格的 NSTableView.我创建了一个自定义 NSTableViewCell 类并将这些行放在它的 drawRect 方法中.

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

这篇关于NSVisualEffectView 上的 NSButton:背景颜色错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆