Guest User

Untitled

a guest
Jan 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. class NowTextField: NSTextField {
  2.  
  3. override func draw(_ dirtyRect: NSRect) {
  4. super.draw(dirtyRect)
  5.  
  6. // required nonsense
  7. let textFieldLayer = CALayer()
  8. let textFieldRect = NSRect(x: 0, y: 0, width: 120, height: 32)
  9. let textFieldTrackingArea = NSTrackingArea.init(rect: textFieldRect, options: [NSTrackingAreaOptions.activeInActiveApp, NSTrackingAreaOptions.mouseEnteredAndExited], owner: self, userInfo: nil)
  10. self.wantsLayer = true
  11. self.layer = textFieldLayer
  12. self.addTrackingArea(textFieldTrackingArea)
  13.  
  14. // styling
  15. self.textColor = NSColor.darkGray
  16. self.layer?.cornerRadius = 4
  17. self.layer?.backgroundColor = NSColor.white.cgColor
  18. self.layer?.borderColor = NSColor.lightGray.cgColor
  19. self.layer?.borderWidth = 2
  20. self.drawsBackground = false
  21. }
  22.  
  23. override func mouseEntered(with event: NSEvent) {
  24. self.textColor = NSColor.darkGray
  25. self.layer?.cornerRadius = 4
  26. self.layer?.backgroundColor = NSColor.white.cgColor
  27. self.layer?.borderColor = NSColor.highlightBlue.cgColor
  28. self.layer?.borderWidth = 2
  29. self.drawsBackground = false
  30. }
  31.  
  32. override func mouseExited(with event: NSEvent) {
  33. self.textColor = NSColor.darkGray
  34. self.layer?.cornerRadius = 4
  35. self.layer?.backgroundColor = NSColor.white.cgColor
  36. self.layer?.borderColor = NSColor.lightGray.cgColor
  37. self.layer?.borderWidth = 2
  38. self.drawsBackground = false
  39. }
  40. }
  41.  
  42. class NowTextField: NSTextField {
  43.  
  44. override func draw(_ dirtyRect: NSRect) {
  45. super.draw(dirtyRect)
  46.  
  47. // required nonsense
  48. let textFieldRect = NSRect(x: 0, y: 0, width: 120, height: 32)
  49. let textFieldTrackingArea = NSTrackingArea.init(rect: textFieldRect, options: [NSTrackingAreaOptions.activeInActiveApp, NSTrackingAreaOptions.mouseEnteredAndExited], owner: self, userInfo: nil)
  50. self.wantsLayer = true
  51. self.addTrackingArea(textFieldTrackingArea)
  52.  
  53. // styling
  54. self.textColor = NSColor.darkGray
  55. self.layer?.cornerRadius = 4
  56. self.layer?.backgroundColor = NSColor.white.cgColor
  57. self.layer?.borderColor = NSColor.lightGray.cgColor
  58. self.layer?.borderWidth = 2
  59. self.drawsBackground = false
  60. }
  61.  
  62. override func mouseEntered(with event: NSEvent) {
  63. self.textColor = NSColor.darkGray
  64. self.layer?.cornerRadius = 4
  65. self.layer?.backgroundColor = NSColor.white.cgColor
  66. self.layer?.borderColor = NSColor.highlightBlue.cgColor
  67. self.layer?.borderWidth = 2
  68. self.drawsBackground = false
  69. }
  70.  
  71. override func mouseExited(with event: NSEvent) {
  72. self.textColor = NSColor.darkGray
  73. self.layer?.cornerRadius = 4
  74. self.layer?.backgroundColor = NSColor.white.cgColor
  75. self.layer?.borderColor = NSColor.lightGray.cgColor
  76. self.layer?.borderWidth = 2
  77. self.drawsBackground = false
  78. }
Add Comment
Please, Sign In to add comment