2016-03-08 103 views
1

我在視圖中的一些無邊界NSButtons,透明彈出窗口上有問題。第一次打開彈出窗口時,這些按鈕看起來應該完全一樣,但當彈出窗口(或其內部的視圖)獲得焦點時,背景變得透明。 它被打開的第一時間,它看起來像這樣(如它應該):enter image description hereNSButton背景獲得焦點後透明

但當酥料餅獲得焦點,按鈕結束這樣的: enter image description here,其中所述背景是透明的和下方的所述內容popover是可見的。

我已經嘗試過以下,我發現散落各地的網絡:

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,當然,右邊的一個。我只嘗試使用上面的一些代碼,但是不幸的是,這個代碼的每一個變體似乎都不能解決它。

有沒有人有任何想法如何避免這種情況?並且有人知道爲什麼垃圾按鈕沒有相同的問題?

在此先感謝!

回答

5

以下是測試NSTextField,但也應該爲按鈕工作。

NSButtonappearance財產設置爲NSAppearanceNameAqua。因爲如果按鈕不嘗試做一些奇怪的活力效果,他不能搞砸。標籤看起來仍然一樣,奇怪的效果消失了。

我在碼字:

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

它的工作原理!非常感謝你!當然,作爲斯威夫特,它看起來像這樣:optionsButton.appearance = NSAppearance(名爲:NSAppearanceNameAqua) –

+0

男人,我希望我能給你100分,這使我的一週。 – Shizam

1

更新時間:SWIFT 4

以下是NSButton測試:

NameofButton.appearance = NSAppearance(named: NSAppearance.Name.aqua)