Skip to content

Instantly share code, notes, and snippets.

@xhruso00
Created August 6, 2021 10:20
Show Gist options
  • Save xhruso00/426b3e87870373b75f87823da6d88bea to your computer and use it in GitHub Desktop.
Save xhruso00/426b3e87870373b75f87823da6d88bea to your computer and use it in GitHub Desktop.
import Cocoa
class SomeView : NSView {
var trackingArea : NSTrackingArea?
override func draw(_ dirtyRect: NSRect) {
NSColor.red.setFill()
dirtyRect.fill()
}
override func updateTrackingAreas() {
super.updateTrackingAreas()
if trackingArea != nil {
removeTrackingArea(trackingArea!)
}
let aTrackingArea = NSTrackingArea(rect: bounds, options: [.cursorUpdate, .activeAlways], owner: self, userInfo: nil)
addTrackingArea(aTrackingArea)
self.trackingArea = aTrackingArea
}
override func cursorUpdate(with event: NSEvent) {
NSCursor.pointingHand.set()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment