NSTextView水平滚动将在行号视图上滚动

时间:2020-05-31 02:42:32

标签: cocoa appkit nstextview nsscrollview

当我在文本视图中启用水平滚动时,内容将在“垂直标尺”视图上方滚动。理想情况下,它不应与行号视图重叠。

这是它的样子

Text overscroll


为了实现水平滚动,我在NSTextView上编写了一个扩展

public extension NSTextView {
    func wrapText(_ isWrapped: Bool) {
        guard let scrollView = enclosingScrollView else { return }
        scrollView.hasHorizontalScroller = !isWrapped
        isHorizontallyResizable = !isWrapped
        let width = isWrapped ? Int(scrollView.contentSize.width) : Int.max
        maxSize = NSSize(width: width, height: Int.max)
        textContainer?.size = NSSize(width: width, height: Int.max)
        textContainer?.widthTracksTextView = isWrapped
    }
}

textView.enclosingScrollView!.hasVerticalRuler = true

0 个答案:

没有答案
相关问题