Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying text in a NSScrollView (Swift)

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?

like image 850
ixany Avatar asked Aug 07 '14 09:08

ixany


1 Answers

@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
like image 141
madx Avatar answered Oct 06 '22 18:10

madx