Declaration
import { TextEditor } from 'swiftui-react-native';nonisolated struct TextEditorInitializers
One SwiftUI initializer backs <TextEditor>.
<TextEditor
text: Binding<string>
/>nonisolated init(text: Binding<String>)text*Binding<string>
Also takes the common view props: modifiers, style and testID.
Overview
A text editor view allows you to display and edit multiline, scrollable
text in your app's user interface. By default, the text editor view styles
the text using characteristics inherited from the environment, like
View.font(_:), View.foregroundColor(_:), and
View.multilineTextAlignment(_:). The text editor view supports
attributed text formatting when initialized with
init(text:selection:)-(Binding<AttributedString>,_).
You create a text editor by adding a TextEditor instance to the
body of your view, and initialize it by passing in a
Binding to a string variable in your app:
struct TextEditingView: View {
@State private var fullText: String = "This is some editable text..."
var body: some View {
TextEditor(text: $fullText)
}
}To style the text, use the standard view modifiers to configure a system font, set a custom font, or change the color of the view's text.
In this example, the view renders the editor's text in gray with a custom font:
struct TextEditingView: View {
@State private var fullText: String = "This is some editable text..."
var body: some View {
TextEditor(text: $fullText)
.foregroundColor(Color.gray)
.font(.custom("HelveticaNeue", size: 13))
}
}If you want to change the spacing or font scaling aspects of the text, you
can use modifiers like View.lineSpacing(_:) and
View.minimumScaleFactor(_:) to configure
how the view displays text depending on the space constraints. For example,
here the View.lineSpacing(_:) modifier sets the spacing between lines
to 5 points:
struct TextEditingView: View {
@State private var fullText: String = "This is some editable text..."
var body: some View {
TextEditor(text: $fullText)
.foregroundColor(Color.gray)
.font(.custom("HelveticaNeue", size: 13))
.lineSpacing(5)
}
}Text formatting
When initialized with init(text:selection:)-(Binding<AttributedString>,_),
TextEditor supports editing and formatting styled text.
By default, TextEditor shows system text formatting controls in the
context menu and in the keyboard toolbar on iOS.
Use View.textInputFormattingControlVisibility(_:for:) to configure
visibility of system text formatting controls.
For more information on formatting attributed text with TextEditor, see
init(text:selection:)-(Binding<AttributedString>,_).
From Apple’s SwiftUI documentation. Code samples there are Swift.
Relationships
Conforms to
- View
See also
More in Controls.
- ButtonA control that initiates an action.
- ColorPickerA control used to select a color from the system color picker UI.
- DatePickerA control for selecting an absolute date.
- DisclosureGroupA view that shows or hides another content view, based on the state of a disclosure control.
- MultiDatePickerA control for picking multiple dates.
- OutlineGroupA structure that computes views and disclosure groups on demand from an underlying collection of tree-structured, identified data.
- PasteButtonA system button that reads items from the pasteboard and delivers it to a closure.
- PickerA control for selecting from a set of mutually exclusive values.
- SecureFieldA control into which people securely enter private text.
- SliderA control for selecting a value from a bounded linear range of values.
- StepperA control that performs increment and decrement actions.
- SubscriptionViewA view that subscribes to a publisher with an action.