如何在 NSPopOver 中更改 NSTextField 背景颜色
How to change NSTextField background color in NSPopOver
Mac OSX 10.10 Xcode 6.1
我在 NSPopOver 中创建了一个表视图。
我尝试更改文本字段的背景颜色。为什么?没有效果。
表格视图的突出显示设置为 "regular"。
哪种方式可以让我将文本字段的背景颜色更改为白色?
文本字段和 Yosemite 中添加的 "vibrancy" 混合存在一个已知错误。众所周知,它会影响弹出框。
解决方法是将 table 视图的 appearance
属性 设置为 NSAppearanceNameAqua
。
这是 confirmed 一位 Apple 工程师在其开发论坛中提出的。
2019-05-09 编辑:
此问题有时还会影响出现在背景为灰色的弹出窗口上的 NSTextFields。这是 Swift 5 修复,将其添加到 popover 控制器的 viewDidLoad() 函数中
self.someTextField.appearance = NSAppearance.init(命名:.aqua)
在我的应用程序中,我遇到了同样的问题。我使用 Swift 并且这对我有用。在您的 viewForTableColumn:
let cell = tableView.makeViewWithIdentifier(tableColumn!.identifier!, owner: self) as! NSTableCellView
cell.textField?.drawsBackground = true
cell.textField?.backgroundColor = NSColor.clearColor()
我真的很喜欢@Prontto 的解决方案,但它不适用于 NSImageView
,因为它没有 drawsBackground
或 backgroundColor
。
幸运的是,外观选项也适用于图像视图!
cell.imageView?.image = image ?? nil
cell.imageView?.appearance = NSAppearance(named: NSAppearanceNameAqua)
Mac OSX 10.10 Xcode 6.1
我在 NSPopOver 中创建了一个表视图。 我尝试更改文本字段的背景颜色。为什么?没有效果。 表格视图的突出显示设置为 "regular"。 哪种方式可以让我将文本字段的背景颜色更改为白色?
文本字段和 Yosemite 中添加的 "vibrancy" 混合存在一个已知错误。众所周知,它会影响弹出框。
解决方法是将 table 视图的 appearance
属性 设置为 NSAppearanceNameAqua
。
这是 confirmed 一位 Apple 工程师在其开发论坛中提出的。
2019-05-09 编辑:
此问题有时还会影响出现在背景为灰色的弹出窗口上的 NSTextFields。这是 Swift 5 修复,将其添加到 popover 控制器的 viewDidLoad() 函数中
self.someTextField.appearance = NSAppearance.init(命名:.aqua)
在我的应用程序中,我遇到了同样的问题。我使用 Swift 并且这对我有用。在您的 viewForTableColumn:
let cell = tableView.makeViewWithIdentifier(tableColumn!.identifier!, owner: self) as! NSTableCellView
cell.textField?.drawsBackground = true
cell.textField?.backgroundColor = NSColor.clearColor()
我真的很喜欢@Prontto 的解决方案,但它不适用于 NSImageView
,因为它没有 drawsBackground
或 backgroundColor
。
幸运的是,外观选项也适用于图像视图!
cell.imageView?.image = image ?? nil
cell.imageView?.appearance = NSAppearance(named: NSAppearanceNameAqua)