简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM