Swift---TextView用法

时间:2016-04-25 10:27:25   收藏:0   阅读:403

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))

}

原文:http://www.cnblogs.com/tt2015-sz/p/5049643.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!