在 SwiftUI 中,为 TextEditor
设置背景颜色可以使用 background
修饰符。以下是一个示例:
struct ContentView: View {
@State private var text = ""
var body: some View {
TextEditor(text: $text)
.background(Color.gray.opacity(0.2))
}
}
在上面的代码中,将 TextEditor
的背景颜色设置为灰色的透明度为0.2。您可以根据需要更改背景颜色。