【问题标题】:Show line numbers in macOS SwiftUI TextEditor在 macOS SwiftUI TextEditor 中显示行号
【发布时间】:2021-03-07 04:25:37
【问题描述】:

我正在使用 SwiftUI 为 macOS 创建一个基于文档的应用程序。

是否有用于显示 TextEditor 行号的内置样式方法?

struct ContentView: View {
    @Binding var document: AppDocument

    var body: some View {
        TextEditor(text: $document.text) // I removed a few irrelevant options.
            .disableAutocorrection(true)
            .font(.system(size: 12, design: .monospaced))
    }
}

当前视图如下:

【问题讨论】:

  • 您可能必须包装 NSTextView 才能做到这一点(或者至少可靠地做到这一点)

标签: swift swiftui


【解决方案1】:

不,TextEditor 没有显示行号的方法。

您可以通过这两个链接自行确认。

文本编辑器

一个可以显示和编辑长文本的视图。

https://developer.apple.com/documentation/swiftui/texteditor

外观和行为

配置视图的文本、控件和其他内容。

https://developer.apple.com/documentation/swiftui/view-appearance-and-behavior

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-28
    • 2021-10-04
    • 1970-01-01
    • 1970-01-01
    • 2021-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多