![]() The “Your score was” text view updates only when the user presses Return.Regardless of which code option you choose, if you try using it you’ll notice a few things: textFieldStyle(RoundedBorderTextFieldStyle()) ![]() TextField("Enter your score", value: $score, formatter: formatter) roundedBorder, and also create a custom number formatter, like this: struct ContentView: View private var score = 0 Important: If you’re using Xcode 12 you need to use RoundedBorderTextFieldStyle() rather than. TextField("Enter your score", value: $score, format. Here’s the code: struct ContentView: View private var score = 0 To demonstrate the functionality – and also its limitations – we could write some code to let the user enter a score in a game, and show what they entered. ![]() You can attach a formatter to SwiftUI’s TextField in order to restrict what kind of data it can contain, but honestly it’s a bit limited in what it can do.
0 Comments
Leave a Reply. |