Swiftpack.co - Package - kenmueller/TextView

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<String>
  • isEditing: Binding<Bool>
    • 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

import SwiftUI
import TextView

struct 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...

Github

link
Stars: 98

Dependencies

Used By

Total: 0

Releases

v1.4.7 - 2020-05-27 22:43:08

shouldChange handler

0e5590be0b58daab3ee366f68ba4a0ab44580fb7

v1.4.6 - 2020-05-25 22:04:37

Added text padding

6dd1a91766ce5328241a33d806df34f81cd6837b

v1.4.5 - 2020-05-13 18:33:37

Fixed cursor position on text update

02f1d069d4e8cfb708edc5cb481da00d437bdd01

v1.4.4 - 2020-04-11 04:25:31

Fixed self.

b6f475e8e0f6caa4249395190b03e66ba826e54b

v1.4.3 - 2020-04-11 01:36:09

Reverted unintentional change

3a9b7f0be4b63fa80e09d511f0ead2cfed9498fc

v1.4.2 - 2020-04-11 01:31:06

Updates first responder status on main thread

2a5118f4856b0868a169f7a28e78eb25fd579a3f

v1.4.1 - 2020-04-11 01:25:13

Fixed placeholder click in new SwiftUI update

41eb93bc6e8868a8d4f0c35c908f34667319cde2

v1.4.0 - 2020-03-30 06:10:58

Better default colors

9495a49164095926c4859d38106e48b3e7c9a103

v1.3.0 - 2020-02-26 07:25:51

Added a placeholder

155e003ddfefc0e8ba9c6f68a4b19359c587fd39

v1.2.0 - 2020-01-06 03:28:17

Added platforms to Package.swift

cb641ab266110069409c1da945333742b98487f2

v1.1.0 - 2019-11-17 19:51:52

Removed second init and updated README for new inputs

Commit d1dc2006fa5a1ddbe458ab730a39569260c4ffc1

v1.0.0 - 2019-11-17 19:21:48

Version 1.0.0

Commit e0c3dda235a66b245e9f03b3619c0be293e1a182