Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent background of NSTextfield NSPopover [duplicate]

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
}
like image 272
Kaunteya Avatar asked Apr 07 '15 13:04

Kaunteya


1 Answers

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.

like image 199
Taylor Avatar answered Nov 08 '22 18:11

Taylor