【问题标题】:How to Set the Paragraph Property Width of NSTextView如何设置 NSTextView 的段落属性宽度
【发布时间】:2019-02-20 17:45:05
【问题描述】:
【问题讨论】:
标签:
cocoa
nstextview
nsparagraphstyle
【解决方案1】:
您可以通过在 NSLayoutManager 子类中覆盖 fillBackgroundRectArray(_: count:forCharacterRange:color:) 来修改选择的绘制矩形。
class MyLayoutManager: NSLayoutManager {
override func fillBackgroundRectArray(_ rectArray: UnsafePointer<NSRect>, count rectCount: Int, forCharacterRange charRange: NSRange, color: NSColor) {
// selection rects to draw a highlight.
var rects: [NSRect] = Array(UnsafeBufferPointer(start: rectArray, count: rectCount))
// modify rects here...
// call super and pass in your custom rects array.
super.fillBackgroundRectArray(&rects, count: rectCount, forCharacterRange: charRange, color: color)
}
}
你可以实现这样的目标:
顺便说一句,您可以使用以下方法替换文本视图的布局管理器:
textView.textContainer?.replaceLayoutManager(MyLayoutManager())