Just started to learn Swift and created a little macOS app in which I want to use a NSScrollView
to display an attributed String. I’ve tried:
@IBOutlet var ScrollViewOutlet : NSScrollView
var attributedString = NSMutableAttributedString(string: myText)
ScrollViewOutlet.insertText(attributedString)
But that doesn’t seem to work. Feels confusing since doing the exact same with a NSTextView
instead works like a charm.
What am I missing here?
@IBOutlet weak var scrollView: NSScrollView!
The documentView
of the NSScrollView
is an NSTextView
, so in Swift you can use the following:
let textView : NSTextView? = scrollView?.documentView as? NSTextView
textView?.string = text
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