I have a simple NSTextView
, which looks like a hyperlink and I want to change the cursor on the pointer when the user hovers this NSTextView
. How can I do it? I know about NSCursor, but apple docs suck and have no examples, I cannot get how to use it.
Here is my NSTextView
:
let linkView = NSTextView()
linkView.font = NSFont(name: "SF Pro Display", size: 13)
linkView.isEditable = false
linkView.isFieldEditor = false
linkView.isHidden = false
linkView.string = (URL(string: (data?.link)!)?.host)!
let attributedString = NSMutableAttributedString(string: linkView.string)
let range = NSRange(location: 0, length: linkView.string.count)
let url = URL(string: (data?.link)!)
attributedString.setAttributes([.link: url!], range: range)
linkView.textStorage?.setAttributedString(attributedString)
linkView.linkTextAttributes = [.underlineStyle: NSUnderlineStyle.styleSingle.rawValue]
Try this, it works for me: