我正在尝试为NSTextView指定行数.我的设计师要求最多两行文字.我已经尝试过NSMutableParagraph样式来添加我想要的省略号截断,但是使用NSMutableParagraph我只能得到带有1行的NSTextView而没有NSMutableParagraph,我得到一个滚动文本,其中包含完成文本所需的行数.
var attributedString = NSMutableAttributedString(string: "This is my text, I can keep going for many characters")
var para = NSMutableParagraphStyle()
para.lineBreakMode = NSLineBreakMode.ByTruncatingTail
let globalAttributes = [
NSParagraphStyleAttributeName: para
]
let range = NSRange(location:0, length: attributedString.length)
attributedString.addAttributes(globalAttributes, range: range)
cellView.myTextView!.textStorage?.setAttributedString(attributedString)
Run Code Online (Sandbox Code Playgroud)
我在NSTextView上尝试过高度限制.我试过了:
cellView.myTextView!.textContainer?.containerSize = NSMakeSize(300, 32)
Run Code Online (Sandbox Code Playgroud)
我已经尝试为NSScrollView创建IBOutlet NSTextView并调整其高度.获得两条线和截断都没有运气.任何帮助是极大的赞赏.我觉得我只是错过了方法或设置.谢谢!
macos cocoa nstextview nsmutableattributedstring nsparagraphstyle