I am developing a Mac application in XCode. I need to add a hyperlink which navigates to a particular site. I tried this using a button, but I need to know how to change the cursor to hand cursor when mouse is over that button.
I believe you can use a non-editable NSTextField to display the URL. If you set the attributes appropriately on the NSAttributedString that you set as the field's value property, it will display as the standard blue-with-underline and handle the cursor tracking for you. This Apple Q&A tells you how to set the attributes for a URL.
To set the cursor, you have to use the cursor tracking method addCursorRect:cursor:
. However, you are really only supposed to call that method from inside the resetCursorRects
method. If you do it at any other time, it's basically guaranteed to be ignored.
So this means you need to subclass NSButton
(or whatever NSView
subclass you want to use) and override resetCursorRects
to call addCursorRect:cursor:
for the entire view's bounds
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With