-1

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 Answers1

1

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)
    }
}
Chus
  • 146
  • 7
  • Yes it is working but my buttons are not programatically created , they created using interface builder . How to do then ? – jis thottan Jul 24 '20 at 03:59