Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class NowTextField: NSTextField {
- override func draw(_ dirtyRect: NSRect) {
- super.draw(dirtyRect)
- // required nonsense
- let textFieldLayer = CALayer()
- let textFieldRect = NSRect(x: 0, y: 0, width: 120, height: 32)
- let textFieldTrackingArea = NSTrackingArea.init(rect: textFieldRect, options: [NSTrackingAreaOptions.activeInActiveApp, NSTrackingAreaOptions.mouseEnteredAndExited], owner: self, userInfo: nil)
- self.wantsLayer = true
- self.layer = textFieldLayer
- self.addTrackingArea(textFieldTrackingArea)
- // styling
- self.textColor = NSColor.darkGray
- self.layer?.cornerRadius = 4
- self.layer?.backgroundColor = NSColor.white.cgColor
- self.layer?.borderColor = NSColor.lightGray.cgColor
- self.layer?.borderWidth = 2
- self.drawsBackground = false
- }
- override func mouseEntered(with event: NSEvent) {
- self.textColor = NSColor.darkGray
- self.layer?.cornerRadius = 4
- self.layer?.backgroundColor = NSColor.white.cgColor
- self.layer?.borderColor = NSColor.highlightBlue.cgColor
- self.layer?.borderWidth = 2
- self.drawsBackground = false
- }
- override func mouseExited(with event: NSEvent) {
- self.textColor = NSColor.darkGray
- self.layer?.cornerRadius = 4
- self.layer?.backgroundColor = NSColor.white.cgColor
- self.layer?.borderColor = NSColor.lightGray.cgColor
- self.layer?.borderWidth = 2
- self.drawsBackground = false
- }
- }
- class NowTextField: NSTextField {
- override func draw(_ dirtyRect: NSRect) {
- super.draw(dirtyRect)
- // required nonsense
- let textFieldRect = NSRect(x: 0, y: 0, width: 120, height: 32)
- let textFieldTrackingArea = NSTrackingArea.init(rect: textFieldRect, options: [NSTrackingAreaOptions.activeInActiveApp, NSTrackingAreaOptions.mouseEnteredAndExited], owner: self, userInfo: nil)
- self.wantsLayer = true
- self.addTrackingArea(textFieldTrackingArea)
- // styling
- self.textColor = NSColor.darkGray
- self.layer?.cornerRadius = 4
- self.layer?.backgroundColor = NSColor.white.cgColor
- self.layer?.borderColor = NSColor.lightGray.cgColor
- self.layer?.borderWidth = 2
- self.drawsBackground = false
- }
- override func mouseEntered(with event: NSEvent) {
- self.textColor = NSColor.darkGray
- self.layer?.cornerRadius = 4
- self.layer?.backgroundColor = NSColor.white.cgColor
- self.layer?.borderColor = NSColor.highlightBlue.cgColor
- self.layer?.borderWidth = 2
- self.drawsBackground = false
- }
- override func mouseExited(with event: NSEvent) {
- self.textColor = NSColor.darkGray
- self.layer?.cornerRadius = 4
- self.layer?.backgroundColor = NSColor.white.cgColor
- self.layer?.borderColor = NSColor.lightGray.cgColor
- self.layer?.borderWidth = 2
- self.drawsBackground = false
- }
Add Comment
Please, Sign In to add comment