为什么在将TextField设置为使用定义的颜色后,TextField的背景仍保持白色?为什么仍然覆盖白色?
import SwiftUI
struct ContentView: View {
@State var search: String = ""
var body: some View {
ZStack{
Color.baseColour
.edgesIgnoringSafeArea(.all)
VStack(alignment: .center, spacing: 0) {
HStack(alignment: .center, spacing: 0) {
TextField("Search for a profile... ", text: $search)
.textFieldStyle(RoundedBorderTextFieldStyle())
.cornerRadius(15)
.background(Color.textFieldBarColour)
}
.frame(width: UIScreen.main.bounds.width - 30)
.background(Color.textFieldBarColour)}
答案 0 :(得分:1)
可以使用纯文本字段样式,如下所示(您的自定义颜色刚刚被替换为演示用)
TextField("Search for a profile... ", text: $search)
.textFieldStyle(PlainTextFieldStyle())
.padding(8)
.background(RoundedRectangle(cornerRadius: 15).fill(Color.yellow))