Transparent background of NSTextfield NSPopover [duplicate]
Asked Answered
A

1

10

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.) enter image description here

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
}
Apiarist answered 7/4, 2015 at 13:55 Comment(0)
H
14

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.

Harper answered 8/4, 2015 at 1:43 Comment(1)
Sadly it's one of the least obvious things a person mildly new to the platform might suffer.Excise

© 2022 - 2024 — McMap. All rights reserved.