How to change background color of NSTextField in NSPopOver

enter image description here

Mac OSX 10.10 Xcode 6.1

I created a table view in NSPopOver. I am trying to change the background color of a text box. What for? no effect. The tableview element is highlighted as "normal." which can allow me to change the background color of text fields to white?

+7
source share
3 answers

Yosemite adds a known bug with text fields and "vibrancy" blending. It is known that affects popover.

The workaround is to set the appearance property of the table view view to NSAppearanceNameAqua .

This was confirmed by an Apple engineer in their devforums.

EDIT 2019-05-09:

This issue also sometimes affects NSTextFields that appear on pop-ups where the background is gray. Here's the Swift 5 fix, add this to the viewDidLoad () function of your popover controller

self.someTextField.appearance = NSAppearance.init (named: .aqua)

+18
source

In my application, I had the same problem. I used Swift and it worked for me. In your view ForTableColumn:

 let cell = tableView.makeViewWithIdentifier(tableColumn!.identifier!, owner: self) as! NSTableCellView cell.textField?.drawsBackground = true cell.textField?.backgroundColor = NSColor.clearColor() 
+9
source

I really like @Prontto's solution, but it does not work with NSImageView because it does not have drawsBackground or backgroundColor .

Fortunately, the appearance option also works for images!

 cell.imageView?.image = image ?? nil cell.imageView?.appearance = NSAppearance(named: NSAppearanceNameAqua) 
0
source

Source: https://habr.com/ru/post/1215443/


All Articles