首页 > 解决方案 > 如何在 SwiftUI 中制作具有某种风格的文本编辑器?

问题描述

如何在 SwiftUI 中制作具有某种风格的文本编辑器?似乎有一个文本编辑器不能像文本字段那样可定制。

我怎样才能达到这样的结果(这里的用户文本是白色的)?

我的问题是如何将文本颜色设置为白色并在文本编辑器中设置背景颜色。

在此处输入图像描述

标签: swiftxcodeswiftui

解决方案


struct ContentView: View {
    init() {
        UITextView.appearance().backgroundColor = .clear // First, remove the UITextView's backgroundColor.
    }
    @State private var input = ""
    var body: some View {
        ZStack {
            Color.blue.edgesIgnoringSafeArea(.all)
            TextEditor(text: $input)
                .font(.body)
                .foregroundColor(.white) // Text color
                .background(Color.blue) // TextEditor's Background Color
        }
    }
}

推荐阅读