0

I'm trying to add login form to white color view but textfield placeholder can't see well, however on preview it shows up.

I tried to change placeholder color SwiftUI. How to change the placeholder color of the TextField? but it still doesn't shows up well. Could you give me some tip how can I solve this problem?

struct CardView: View {
    var body: some View {
        ZStack {
            Rectangle()
                .fill(Color(UIColor.white))
                .frame(height:300)
                .cornerRadius(10)
                .padding(16)
                 LoginForm()
        }
    }
}

struct LoginForm: View {
@State var username: String = ""
var body: some View {
        VStack(alignment:.center) {
        UsernameTextField(userNumber: $username)
            .padding(50)
        LoginButton()
    }.padding()
}

}

struct UsernameTextField: View {
@Binding var userNumber: String
var body: some View {
    TextField("Phone number", text: $userNumber)
        .padding(50)
        .onChange(of: userNumber, perform: { value in
            userNumber = formatNumberTextField(pattern: "+X(XXX) XXX XX XX", phoneNumber: userNumber)
        })
        .frame(height: 48)
        //.textFieldStyle(DefaultTextFieldStyle())
        .cornerRadius(16)
        .foregroundColor(.black)
        .accentColor(.black)
        .fixedSize(horizontal: true, vertical: false)
        .padding([.leading, .trailing], 10)
        .underlineTextField()
}

enter image description here enter image description here

Abrcd18
  • 155
  • 1
  • 13
  • What is the issue? it seems like you have an issue with the color – Mojtaba Hosseini Sep 28 '21 at 16:57
  • I want to show textfield placeholder as on preview, but it can't see well on simulator – Abrcd18 Sep 28 '21 at 17:01
  • Do you think it's because of color? I tried to use extension as here https://stackoverflow.com/questions/57688242/swiftui-how-to-change-the-placeholder-color-of-the-textfield/62950092 but placeholder is still not showing well :( – Abrcd18 Sep 28 '21 at 17:02
  • In general textfield placeholder should look like this https://imgur.com/a/QRpIxGH I can't understand why placeholder text can't see well as on this screenshot – Abrcd18 Sep 28 '21 at 17:24
  • @MojtabaHosseini Could you please give some tip what may be wrong? – Abrcd18 Sep 29 '21 at 06:34
  • Isolate your code down to a single field (instead of a full view with buttons and cards and etc.) then play with parameters to find the one that suits you – Mojtaba Hosseini Sep 29 '21 at 09:10

0 Answers0