Tootips in NSTextView/NSTextfields

Sak Wathanasin

I want to display tooltips over parts of an attributed string, and thought that using an
NSToolTipAttributeName attribute on the required ranges would do the trick but I can't get it to
work. In my toy (macOS) app, I have a NSTxtView and in my aWakeFromNib, I do

let testString = "Test text with tooltip"
let testNSString = testString as NSString
let tooltipRange = testNSString.range(of: "tooltip")
self.textView.textStorage?.replaceCharacters(in: NSMakeRange(0,
self.textView.textStorage!.length), with: testString)
self.textView.textStorage?.setAttributes([NSAttributedStringKey.toolTip: "sample tooltip
text" as NSString,
NSAttributedStringKey.foregroundColor:], range: tooltipRange)

The word "tooltip" is shown in red as expected, but no tooltip appears when I hover over it. What
am I missing?

Thanks for any help,


Join to automatically receive all group messages.