Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class HighlightColorTextFieldCell : NSTextFieldCell {
var hightlightColor: NSColor? {
didSet {
updateTextColor()
}
}
var nonHighlightedTextColor: NSColor? {
didSet {
updateTextColor()
}
}
override var backgroundStyle: NSView.BackgroundStyle {
didSet {
updateTextColor()
}
}
private func updateTextColor() {
switch backgroundStyle {
case .raised, .emphasized: textColor = hightlightColor
case .lowered, .normal: textColor = nonHighlightedTextColor
}
}
override func setUpFieldEditorAttributes(_ textObj: NSText) -> NSText {
let newTextObj = super.setUpFieldEditorAttributes(textObj)
newTextObj.textColor = NSColor.black
textColor = NSColor.black /* Not sure why the line above is not enough (and actually seems to do nothing...) */
return newTextObj
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.