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:
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?
source to share
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:
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).
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.
source to share
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%.
source to share