Giter Site home page Giter Site logo

thefabulous / formattabletextview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from qiwi/formattabletextview

0.0 0.0 0.0 662 KB

Allows you to format user input according to your mask.

License: MIT License

Swift 97.51% Objective-C 1.33% Ruby 1.16%

formattabletextview's Introduction

ℹī¸ We forked this in order to update the Build Settings "Mach-O Type" to "Dynamic Library". This is required for our Carthage integration on CI, full investigation here.

FormattableTextView

Description

FormattableTextView is a framework which allows you to format user input according to your mask. There are 2 implementations: for UITextView and for UITextField. UITextField is less memory consuming, UITextView is more flexible for customization. You can choose either one.

When you select the text in this field, only your input text is selected because non-input symbols are drawn in other layers.

This approach allows to:

  • prohibit user from putting the cursor in non-input symbols ranges
  • avoid problems when adding/removing symbols inside existing text
  • customize input and non-input attributes separately.

Requirements

  • iOS 8.0+

Installation

CocoaPods

pod 'FormattableTextView', :git => 'https://github.com/qiwi/FormattableTextView'

Carthage

git "https://github.com/qiwi/FormattableTextView" "master"

Usage

Example

let field = FormattableTextField()
field.formatSymbols = ["d": CharacterSet.decimalDigits,
					   "w": CharacterSet.lowercaseLetters]
field.format = "dd.dd.dddd"
field.maskAppearance = .leftOnly
field.inputAttributes = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16)]
field.maskAttributes = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16),
						NSAttributedString.Key.foregroundColor: UIColor.lightGray]

Usage notes

Set the mask with format property. By default d means digits, w means letters and * means any symbol.

Examples:

  • +7(ddd)ddd-dd-dd - phone number format for Russia
  • dd.dd.dddd - date format
  • www*d dd - 3 letters, any symbol, digit and 2 other digits after non-input space

You can set your own custom mapping using formatSymbols property. All other symbols will be considered as non-input.

Non-input symbols have 3 appearance options:

  • leftOnly You will see only those non-input symbols which are located to the left of your inputted symbols

  • leftAndRight You will see only those non-input symbols which are located to the left and to the right of your inputted symbols

  • whole You will see all non-input symbols and placeholders for input symbols. Every key in placeholders parameter must exist among the formatSymbols keys. In this mode inputAttributes and maskAttributes properties have to be the same. Your font must be monospaced.

If you need to set input text programmatically use text property.

For left inset use insetX property.

You can modify input and non-input symbols appearance by using inputAttributes and maskAttributes properties.

License

Distributed under the MIT License.

formattabletextview's People

Contributors

raducanb avatar live-sound avatar antongolub avatar spetruk 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.