Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. // Custom text colors don't automagically invert.
  2. class TableViewTextFieldCell: NSTextFieldCell {
  3.  
  4. private var previousTextColor: NSColor?
  5.  
  6. override var backgroundStyle: NSView.BackgroundStyle {
  7. get {
  8. return super.backgroundStyle
  9. }
  10. set(newBackgroundStyle) {
  11. // If we are going to light because we are selected, save off the old color so we can restore it
  12. if self.backgroundStyle == .light && newBackgroundStyle == .dark {
  13. previousTextColor = self.textColor
  14. self.textColor = NSColor.white // or a named color?
  15. } else if self.backgroundStyle == .dark && newBackgroundStyle == .light {
  16. if previousTextColor != nil {
  17. self.textColor = previousTextColor
  18. previousTextColor = nil
  19. }
  20. }
  21. super.backgroundStyle = newBackgroundStyle
  22.  
  23. }
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement