Strange text color when using custom NSTableRowView in NSVisualEffectView

I am using a custom NSTableRowView in NSVisualEffectView. I have implemented a custom lighlight style in CustomTableRowView like this:

class CustomTableRowView: NSTableRowView {

    override func drawSelection(in dirtyRect: NSRect) {
        if (self.selectionHighlightStyle != NSTableViewSelectionHighlightStyle.none) {
            if self.isEmphasized {
                NSColor(calibratedRed: 26.0/255.0, green: 154.0/255.0, blue: 252.0/255.0, alpha: 1.0).setStroke()
            } else {
                NSColor(calibratedWhite: 0.82, alpha: 1.0).setStroke()
            }

            let selectionPath = NSBezierPath(rect: dirtyRect)
            selectionPath.lineWidth = 3.0
            selectionPath.stroke()
        }
    }

    override var interiorBackgroundStyle: NSBackgroundStyle {
        return NSBackgroundStyle.light
    }
}

      

But the color of the text in the selected line becomes strange and the font becomes bold automatically. See the picture below:

enter image description here

I also put the example code on github . What's wrong with my implementation? How do I make the text color and font weight of the selected line the same as the lines that are not selected?

+3


source to share


2 answers


It looks like the main issue is with the animation level of the visual effect. While that might not be the whole reason for the buggy deselecting behavior for nested views, it did help:

glitchy visual effect view

In addition, there are some other possible areas that can be customized (for example tableCellView

):

tableCellView.textField?.stringValue = "aaaaaaaaaaaaaaaa"
tableCellView.textField?.font = NSFont(name: "Menlo", size: 11)
tableCellView.textField?.textColor = NSColor(white: 0.01, alpha: 0.75)
tableCellView.appearance = NSAppearance(named: NSAppearanceNameAqua)
...

      

It is not clear to me why the text in the View appears to be bold and somewhat overly anti-aliased, although I believe some of them are the result of errors related to the Visual Effect View (see below) ...




By the way, it looks like Xcode itself is affected by similar behavior; in the Xcode Project Navigator, after using the Visual Effect View, sometimes the selected item turns white, which usually does not look normal. I concluded that this is a bug (apparently related to visual effect).

enter image description here

Removing the visual effect solves the text problem, but is not a real solution since you have to use it. Errors and buggy behavior should always be reported to Apple.

0


source


This is due to vibration problems. Yours NSTextFields

tries to be bright, but NSTableRowView

blocks it.

To fix this problem and turn off vibration, set textColor

these text boxes to something other than labelColor

or secondaryLabelColor

.



So, for example, set it to labelColor

in the Interface Builder and then change the opacity to 1%.

0


source







All Articles