The missing TextView in SwiftUI
- File -> Swift Packages -> Add Package Dependency...
- Select your project
- Enter
https://github.com/kenmueller/TextViewfor the package repository URL - Select Branch: master
- Click Finish
text: Binding<String>isEditing: Binding<Bool>- The
TextViewwill modify the value when it is selected and deselected - You can also modify this value to automatically select and deselect the
TextView
- The
placeholder: String? = niltextAlignment: TextView.TextAlignment = .leftplaceholderAlignment: Alignment = .topLeadingplaceholderHorizontalPadding: CGFloat = 4.5placeholderVerticalPadding: CGFloat = 7font: UIFont = .preferredFont(forTextStyle: .body)- By default, the font is a body-style font
textColor: UIColor = .blackplaceholderColor: Color = .graybackgroundColor: UIColor = .whitecontentType: TextView.ContentType? = nil- For semantic purposes only
autocorrection: TextView.Autocorrection = .defaultautocapitalization: TextView.Autocapitalization = .sentencesisSecure: Bool = falseisEditable: Bool = trueisSelectable: Bool = trueisScrollingEnabled: Bool = trueisUserInteractionEnabled: Bool = trueshouldWaitUntilCommit: Bool = true- For multi-stage input methods, setting this to
falsewould make TextView completely unusable. - This option will ignore text changes when the user is still composing characters.
- For multi-stage input methods, setting this to
import SwiftUI
import TextView
struct ContentView: View {
@State var input = ""
@State var isEditing = false
var body: some View {
VStack {
Button(action: {
self.isEditing.toggle()
}) {
Text("\(isEditing ? "Stop" : "Start") editing")
}
TextView(
text: $input,
isEditing: $isEditing,
placeholder: "Enter text here"
)
}
}
}