Updated for Xcode 14.2
SwiftUI’s TextField
view normally lets users write their text in whatever case they want, but if you want to control that you can force either uppercase or lowercase text using the textCase()
modifier.
For example, this asks users to enter their name and uppercases every letter:
struct ContentView: View {
@State private var name = "Paul"
var body: some View {
TextField("Shout your name at me", text: $name)
.textFieldStyle(.roundedBorder)
.textCase(.uppercase)
.padding(.horizontal)
}
}
Download this as an Xcode project
Important: If you’re using Xcode 12 you need to use RoundedBorderTextFieldStyle()
rather than .roundedBorder
.
SPONSORED From March 20th to 26th, you can join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer!
Sponsor Hacking with Swift and reach the world's largest Swift community!
Link copied to your pasteboard.