TextEditor
came to SwiftUI
with the release of iOS 14. It allows us to display and write multi-line scrollable text. We create TextEditor
by Binding it to a string variable.
Let’s work on an example.
struct DevTechieTextEditorExample: View {
@State private var text = "Learn iOS Development with DevTechie.com"
var body: some View {
NavigationStack {
TextEditor(text: $text)
.padding()
.navigationTitle("DevTechie")
}
}
}
By default, TextEditor
view styles the text using characteristics inherited from the environment
.
For example, Font
:
struct DevTechieTextEditorExample: View {
@State private var text = "Learn iOS Development with DevTechie.com"
var body: some View {
NavigationStack {
TextEditor(text: $text)
.font(.title)
.padding()
.navigationTitle("DevTechie")
}
}
}