Reputation: 291
Why does the background of the TextField remain white after I've set it to use a defined colour? Why does it still overlay white?
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)}
Upvotes: 2
Views: 1120
Reputation: 258541
It is possible to do with plain textfield style, like below (your custom colours just replaced with known for demo)
TextField("Search for a profile... ", text: $search)
.textFieldStyle(PlainTextFieldStyle())
.padding(8)
.background(RoundedRectangle(cornerRadius: 15).fill(Color.yellow))
Upvotes: 2