Displaying text in a NSScrollView (Swift)

前端 未结 7 1598
醉酒成梦
醉酒成梦 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:50

    For NSScrollView:

    @IBOutlet weak var textScroll: NSScrollView!
    

    Check this out:

    let text = textScroll.documentView!.textStorage!!
    let attr = NSAttributedString(string: "Hello World")
    
    text.appendAttributedString(attr)
    

    This is very much in spirit of @mrtn.lxo solution, only done for NSScrollView and is using NSAttributedString.

提交回复
热议问题