获得焦点后NSButton背景透明 [英] NSButton background transparent after getting focus

查看:142
本文介绍了获得焦点后NSButton背景透明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在透明弹出框上的视图中,一些无边界的NSButton存在问题。首次打开弹出窗口时,按钮的外观应与预期完全一样,但是当弹出窗口(或其内部的视图)获得焦点时,背景将变为透明。
第一次打开时,它看起来像这样(应该这样):,其中背景是透明的,并且弹出框下面的内容是可见的。



我已经尝试过以下方法,发现分散在网上:

  optionsButton.setButtonType( .MomentaryChangeButton)

optionsButton.cell?.showsFirstResponder = false

let bColor = NSColor(红色:230.0 / 255.0,绿色:230.0 / 255.0,蓝色:230.0 / 255.0, alpha:1.0)
(optionsButton.cell as!NSButtonCell).backgroundColor = bColor
optionsButton.layer?.backgroundColor = bC olor.CGColor

(optionsButton.cell为! NSButtonCell).showsStateBy = .PushInCellMask
(optionsButton.cell as!NSButtonCell).highlightsBy = .ContentsCellMask

optionsButton当然是右边的那个。我尝试仅使用上面的一些代码,但是不幸的是,此方法的每个变体似乎都无法解决!



有人对如何避免这种情况有任何想法?有人知道为什么垃圾按钮没有相同的问题吗?



预先感谢!

解决方案

以下内容已针对NSTextField进行了测试,但也适用于按钮。



设置外观 NSButton 属性设置为 NSAppearanceNameAqua 。因为如果按钮不尝试产生奇怪的振动效果,他就不会搞砸。标签仍然看起来一样,并且奇怪的效果消失了。



我在代码中的单词:

  self.button.appearance = [NSAppearance项目名称:NSAppearanceNameAqua]; 


I have a problem with some borderless NSButtons in a view, on a transparent popover. When the popover is first opened, the buttons look exactly as they should, but when the popover (or the view inside it) gains focus, the background becomes transparent. The first time it is opened, it looks like this (As it should):

But when the popover gains focus, the buttons end up like this: , where the background is transparent and the content beneath the popover is visible.

I already tried the following, which I found scattered around the web:

optionsButton.setButtonType(.MomentaryChangeButton)

optionsButton.cell?.showsFirstResponder = false

let bColor = NSColor(red: 230.0/255.0, green: 230.0/255.0, blue: 230.0/255.0, alpha: 1.0)
(optionsButton.cell as! NSButtonCell).backgroundColor = bColor
optionsButton.layer?.backgroundColor = bColor.CGColor

(optionsButton.cell as! NSButtonCell).showsStateBy = .PushInCellMask
(optionsButton.cell as! NSButtonCell).highlightsBy = .ContentsCellMask

optionsButton is, of course, the one on the right. I tried only using some of the code above, but every variation of this doesn't seem to fix it, unfortunately!

Does anyone have any idea on how to avoid this? And does someone know why the trash-button doesn't have the same problem?

Thanks in advance!

解决方案

The following is tested for NSTextField, but should work for buttons as well.

Set the appearance property of the NSButton to NSAppearanceNameAqua. Because if the button doesn't try to do some weird vibrancy effect, he can't mess things up. The labels still look the same and the strange effect is gone.

My words in code:

self.button.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];

这篇关于获得焦点后NSButton背景透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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