Disclaimer: This question is an extension to this question
I am trying to populate a Table in NSPopover.(As seen in the image)
Problem:
I am not able to make transparent background to NSTextField.
Strangely, it works fine if view is attached to NSWindow
(The names in window at left are having transparent background, but same view when seen in NSPopover fails to show transparent background to NSTextfield.)
Is this a bug in NSPopover or am I doing something wrong ?
This is my code to create Table cells
func tableView(tableView: NSTableView, viewForTableColumn tableColumn: NSTableColumn?, row: Int) -> NSView? {
var cell = NSTableCellView(frame: NSMakeRect(0, 0, 100, 40))
var textField = NSTextField(frame: NSMakeRect(0, 0, 50, 20))
// **For transparency**
textField.stringValue = nameList[row]
textField.bezeled = false
textField.editable = false
textField.drawsBackground = false
cell.addSubview(textField)
return cell
}
This is an issue with the text field being rendered vibrantly, causing the white background of the table view around it to also be rendered vibrantly. This vibrancy causes a plusL blend mode, therefore becoming invisible).
This only happens in a popover because that's a vibrant context, and is setup with an NSAppearanceNameVibrantLight
appearance by default.
Sessions 209 and 220 from WWDC2014 discuss a bit more about vibrancy, and the 10.10 release notes on NSVisualEffectView / vibrancy.
To workaround this, you can set the appearance of the table view to the NSAppearanceNameAqua
appearance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With