Home

Awesome

AnimatedTextInput GitHub version

iOS custom text input component used in the Jobandtalent app.

Installation

Use cocoapods to install this custom control in your project.

pod 'AnimatedTextInput', '~> 0.3.0'

Usage

Use the main class AnimatedTextInput. Create it either by code or dragging a new instance of UIView into your storyboard/nib file and setting its class in the identity inspector.

Types

Currently there are 6 different types, defined in the AnimatedTextInputType enum.

To switch between types, you can simply use the type property assining one of the values available in the AnimatedTextInputType enum.

textInput.type = .numeric

Styles

Creating a new visual style is as easy as creating a new struct that conforms to the AnimatedTextInputStyle protocol.

For example:


struct CustomTextInputStyle: AnimatedTextInputStyle {

    let activeColor = UIColor.orangeColor()
    let inactiveColor = UIColor.grayColor().colorWithAlphaComponent(0.3)
    let errorColor = UIColor.redColor()
    let textInputFont = UIFont.systemFontOfSize(14)
    let textInputFontColor = UIColor.blackColor()
    let placeholderMinFontSize: CGFloat = 9
    let counterLabelFont: UIFont? = UIFont.systemFontOfSize(9)
    let leftMargin: CGFloat = 25
    let topMargin: CGFloat = 20
    let rightMargin: CGFloat = 0
    let bottomMargin: CGFloat = 10
    let yHintPositionOffset: CGFloat = 7
}

Then, use the style property to set it.

textInput.style = CustomTextInputStyle()

Other considerations

Download and check the Example project for more examples.


One last question: Why create a TextInput abstraction and not use UITextField or UITextView instead?

From an API point of view, we only wanted to deal with one control. However, we needed some behaviours that were not supported by UITextField or UITextView. For instance, we wanted AnimatedTextInput to support multiline, but UITextField does not support it. We also wanted secure text entry for the password type, but UITextView does not support it. That's why we ended up creating TextInput abstraction.

FAQ

  1. How do I enable autocorrection (or any property available in UITextField or UITextView)? https://github.com/jobandtalent/AnimatedTextInput/issues/67