Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kenmueller/textview
The missing TextView in SwiftUI
https://github.com/kenmueller/textview
Last synced: 3 days ago
JSON representation
The missing TextView in SwiftUI
- Host: GitHub
- URL: https://github.com/kenmueller/textview
- Owner: kenmueller
- License: mit
- Created: 2019-11-09T05:26:11.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-10-15T03:07:38.000Z (about 3 years ago)
- Last Synced: 2024-12-26T17:07:07.179Z (10 days ago)
- Language: Swift
- Homepage:
- Size: 35.2 KB
- Stars: 248
- Watchers: 7
- Forks: 32
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TextView
> The missing TextView in SwiftUI
## Download
- File -> Swift Packages -> Add Package Dependency...
- Select your project
- Enter `https://github.com/kenmueller/TextView` for the package repository URL
- Select **Branch**: master
- Click **Finish**## Inputs
- `text: Binding`
- `isEditing: Binding`
- The `TextView` will modify the value when it is selected and deselected
- You can also modify this value to automatically select and deselect the `TextView`
- `placeholder: String? = nil`
- `textAlignment: TextView.TextAlignment = .left`
- `textHorizontalPadding: CGFloat = 0`
- `textVerticalPadding: CGFloat = 7`
- `placeholderAlignment: Alignment = .topLeading`
- `placeholderHorizontalPadding: CGFloat = 4.5`
- `placeholderVerticalPadding: CGFloat = 7`
- `font: UIFont = .preferredFont(forTextStyle: .body)`
- By default, the font is a body-style font
- `textColor: UIColor = .black`
- `placeholderColor: Color = .gray`
- `backgroundColor: UIColor = .white`
- `contentType: TextView.ContentType? = nil`
- For semantic purposes only
- `autocorrection: TextView.Autocorrection = .default`
- `autocapitalization: TextView.Autocapitalization = .sentences`
- `isSecure: Bool = false`
- `isEditable: Bool = true`
- `isSelectable: Bool = true`
- `isScrollingEnabled: Bool = true`
- `isUserInteractionEnabled: Bool = true`
- `shouldWaitUntilCommit: Bool = true`
- For multi-stage input methods, setting this to `false` would make the `TextView` completely unusable.
- This option will ignore text changes when the user is still composing characters.
- `shouldChange: TextView.ShouldChangeHandler? = nil`
- Of type `(NSRange, String) -> Bool` and is called with the arguments to `textView(_:shouldChangeTextIn:replacementText:)`.## Example
```swift
import SwiftUI
import TextViewstruct ContentView: View {
@State var text = ""
@State var isEditing = false
var body: some View {
VStack {
Button(action: {
self.isEditing.toggle()
}) {
Text("\(isEditing ? "Stop" : "Start") editing")
}
TextView(
text: $text,
isEditing: $isEditing,
placeholder: "Enter text here"
)
}
}
}
```## You might also find these useful...
- [**Audio** - _The easiest way to play Audio in Swift_](https://github.com/kenmueller/Audio)