Created
September 5, 2018 09:00
-
-
Save Frizlab/0f79fd7f1663e95455a24902c502805b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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