On mouse hover on NSButton Change Cursor (for OSX)

403 Views Asked by At

I made a subclass of NSButton

class Button: NSButton {
        var cursor = NSCursor()
       override func resetCursorRects() {
           
           super.resetCursorRects()
           addCursorRect(bounds, cursor: .pointingHand)
       }
   }

on my VC class i have added

let tempBtn = Button()

to call subclass but still no use. What am i doing wrong.

1

There are 1 best solutions below

1
On

This works for me.

class ViewController: NSViewController {

    class Button: NSButton {
        override func resetCursorRects() {
            super.resetCursorRects()
            addCursorRect(bounds, cursor: .pointingHand)
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        let button = Button(frame: CGRect(x: 100, y: 100, width: 100, height: 50))
        view.addSubview(button)
    }
}