我正在尝试指定 NSTextView 的行数。我的设计师要求最多 2 行文本。我已经尝试过 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)
我在 NSTextView 上尝试过高度限制。我试过了:
cellView.myTextView!.textContainer?.containerSize = NSMakeSize(300, 32)
我尝试为 NSTextView 所在的 NSScrollView 创建 IBOutlet 并调整其高度。获得 2 行和截断都没有运气。任何帮助是极大的赞赏。我觉得我只是缺少一种方法或设置。谢谢!