Code Monkey home page Code Monkey logo

textview's Introduction

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

textview's People

Contributors

kenmueller avatar wearhere avatar laosb avatar emmceemoore avatar ebaujard avatar ejensen avatar jackyoustra avatar icomputerfreak avatar maail avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.