Displaying text in a NSScrollView (Swift)

前端 未结 7 1599
醉酒成梦
醉酒成梦 2020-12-10 05:14

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:

@I         


        
7条回答
  •  生来不讨喜
    2020-12-10 05:48

    In the following example, I added the scrollView in the interface builder as my starting point.

    The following works if you your scrollView/textView is empty/blank OR if you need to append text in front of what is already in the scrollView/textView. If there is already text in the box, the new text is inserted in front of the existing text.

    The documentView is an NSTextView

    Swift 4.0

    @IBOutlet weak var imageDestinationDirectory: NSScrollView!
    
    ...
    
    let destinationText = "Text to display"
    imageDestinationDirectory.documentView!.insertText(destinationText)
    

提交回复
热议问题