为配合其他控件,我的文本字段使用了框架,框架的高度大于文本本身的高度。标准视图显示在带有自定义占位符的示例上方文本字段中。当我单击“文本字段”时,较小的文本区域本身具有灰色背景:
如何将此文本背景设置为纯色?
struct TestView: View {
@State var city: String
@State var street: String
var body: some View {
VStack{
ZStack(alignment: .center) {
if city.isEmpty { Text("Bitte Namen eingeben")
.font(.system(size: 24,weight: .heavy,design: .default))
.foregroundColor(Color( red: 1.0,green: 0.0,blue: 0.0,opacity: 0.3))
}
TextField("",text: self.$city)
.textFieldStyle(CustomTFStyle())
}
ZStack(alignment: .center) {
if street.isEmpty { Text("Bitte Strasse eingeben")
.font(.system(size: 24,text: self.$street)
.textFieldStyle(CustomTFStyle())
}
}
}
}
public struct CustomTFStyle : TextFieldStyle {
public func _body(configuration: TextField<Self._Label>) -> some View {
configuration
.accentColor(.black)
.frame(width: 300,height: 70,alignment: .center)
.border(Color.gray,width: 4)
.font(.system(size: 30,design: .default))
.clipShape(RoundedRectangle(cornerRadius: 12))
.shadow(radius: 12)
.foregroundColor(.black)
}
}