ChristianVirtual
ChristianVirtual

Reputation: 81

difference between background color for TextField in SwiftUI between macOS and iOS?

I run into an issue I have no idea how to solve. I plan to have a shared code base for macOS and iOS with SwiftUI (as much as possible).

But already with something simple like setting background color for a text field there is a difference

Following code snippet:

struct NewTextField : View
{
   @State var d:String = ""
   
   var body: some View
   {
      HStack(content:
      {
         TextField("Date: ", text:$d)
            .foregroundColor(.black)
            .background(Color.green)
         /// ... more views
      }
   } 
}

This is simplified; I have multiple textfields on the real application with background colors depending on the content.

on iOS it looks ok; the full textfield background is set to the desired color; on macOS the TextField appear with white background and colored border.

What I'm doing wrong ?

Upvotes: 0

Views: 1639

Answers (1)

ChristianVirtual
ChristianVirtual

Reputation: 81

just to leave it not unanswered:

added

.textFieldStyle(PlainTextFieldStyle()) 

and it create the desired effect

TextField("Date: ", text:$d)
.textFieldStyle(PlainTextFieldStyle()) 
.foregroundColor(.black) 
.background(Color.green) 

based on this post: SwiftUI customized text field in OSX

Upvotes: 3

Related Questions