< How to create a stepper and read values from it | How to let users select a color with ColorPicker > |
Updated for Xcode 14.2
SwiftUI has a TextEditor
view for handling multi-line, scrolling text. You can set the font, change the colors as needed, and even adjust line spacing and how many lines can be created.
You need to store the current value of your text field somewhere, using @State
or similar. For example, we could create a text view to let the user enter profile data like this:
struct ContentView: View {
@State private var profileText = "Enter your bio"
var body: some View {
NavigationStack {
TextEditor(text: $profileText)
.foregroundColor(.secondary)
.padding(.horizontal)
.navigationTitle("About you")
}
}
}
Download this as an Xcode project
For single-line text entry, use TextField
instead.
Tip: In case you were wondering, at this time there is no ability to add formatted text inside a TextEditor
view.
SPONSORED Play is the first native iOS design tool created for designers and engineers. You can install Play for iOS and iPad today and sign up to check out the Beta of our macOS app with SwiftUI code export. We're also hiring engineers!
Sponsor Hacking with Swift and reach the world's largest Swift community!
Link copied to your pasteboard.