Home > Software design >  SwiftUI - rounded textField
SwiftUI - rounded textField

Time:09-21

I have a textField:

TextField("Message...", text: $chatViewModel.composedMessage)
          .frame(height: 30)
          .padding(10)
          .background(RoundedRectangle(cornerRadius: 20))
          .foregroundColor(Color(red: 237/255, green: 237/255, blue: 237/255))

It creates the rounded corner with the correct foregroundColor but the text color is also the same as the foregroundColor.

So if I change this:

.foregroundColor(Color(red: 237/255, green: 237/255, blue: 237/255)) 

to

.foregroundColor(Color.black)

It changes the textfield background colour but also the text color, so I can never see what im actually typing in the textField.

CodePudding user response:

Add file color for RoundedRectangle.

.background(RoundedRectangle(cornerRadius: 20).fill(Color(red: 237/255, green: 237/255, blue: 237/255))) // Here!!
.foregroundColor(.black)

  • Related