Swift---TextView用法


1、TextView放在一个NSScrollView中,作为documentView存在。

@IBOutlet weak var txtScrollView: NSScrollView!

2、在TextView中写入字符串

self.txtScrollView.documentView?.setString("写入第一句。")

3、在TextView中添加字符串

self.txtScrollView.documentView?.textStorage??.mutableString.appendString("追加第二句。")

4、使滚动条自动滑到最下面

if let height=self.txtScrollView.documentView?.bounds.size.height{
   var y=height-self.txtScrollView.documentVisibleRect.height
   if y<0{
      y=0
   }
   self.txtScrollView.contentView.scrollPoint(NSMakePoint(0, y))

}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM