Gurmukh Singh
Gurmukh Singh

Reputation: 2017

SwiftUI - rounded textField

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.

Upvotes: 0

Views: 3304

Answers (3)

Krishna Prajapati
Krishna Prajapati

Reputation: 1

TextField("Email", text: $email)
            .textFieldStyle(.plain)
            .frame(height: 40)
            .clipShape(Capsule())
            .padding()
            .overlay(RoundedRectangle(cornerRadius:10.0).strokeBorder(Color.gray, style: StrokeStyle(lineWidth: 1.0)))
                        .padding()

Upvotes: 0

Andrew
Andrew

Reputation: 11385

2022, SwiftUI 2.0

TextField("File Name", text: $fileName)
    .textFieldStyle(RoundedBorderTextFieldStyle())

Upvotes: 4

Raja Kishan
Raja Kishan

Reputation: 18994

Add file color for RoundedRectangle.

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

Upvotes: 1

Related Questions