在 SwiftUI 中更改 TextEditor 的背景颜色 [英] Change background color of TextEditor in SwiftUI
本文介绍了在 SwiftUI 中更改 TextEditor 的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
TextEditor
似乎有一个默认的白色背景.所以以下不起作用,它显示为 white
而不是定义的 red
:
TextEditor
seems to have a default white background. So the following is not working and it displayed as white
instead of defined red
:
var body: some View {
TextEditor(text: .constant("Placeholder"))
.background(Color.red)
}
是否可以将颜色更改为自定义颜色?
Is it possible to change the color to a custom one?
推荐答案
TextEditor
由 UITextView
支持.所以你需要先去掉 UITextView
的 backgroundColor
然后你可以设置任何 View
到 background
>.
TextEditor
is backed by UITextView
. So you need to get rid of the UITextView
's backgroundColor
first and then you can set any View
to the background
.
struct ContentView: View {
init() {
UITextView.appearance().backgroundColor = .clear
}
var body: some View {
List {
TextEditor(text: .constant("Placeholder"))
.background(Color.red)
}
}
}
演示
你可以在这个答案中找到我发展 TextEditor 这里的简单技巧
这篇关于在 SwiftUI 中更改 TextEditor 的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文