Latest 0.5.2
Homepage https://github.com/jobandtalent/AnimatedTextInput
License MIT
Platforms ios 8.0
Authors

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.

  • Text: basic text input, same behaviour as UITextField.

  • Password: secure text entry and eye button for revealing its content.

  • Numeric: numeric text input.

  • Selection: user interaction for the text input is disabled. A tapAction is expected and called when the text input is pressed. Normally used to present a set of options and modify its state after one option is selected.

  • Multiline: similar behaviour to UITextView with no scrolling. The intrinsicContentSize of the view will grow as the user types. If you need this behaviour and you use autolayout, pin either the bottom or the top, otherwise the view won’t grow (like you would do with a UILabel).

  • Generic: expects a configured TextInput. Use this if you need a UITextField or UITextView with your custom behaviour. Check TextInput and TextInputDelegate protocols and create a class conforming to them.

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

  • You can use AnimatedTextInput as a replacement for either UITextField or UITextView. To set or retrieve the input text, use the text property.

  • This control provides an easy way of setting a counter label. Just call the function showCharacterCounterLabel(with:) and give it a maximum number of characters.

  • AnimatedTextInput has its own delegate methods, very similar to UITextFieldDelegate and UITextViewDelegate.

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

Latest podspec

{
    "name": "AnimatedTextInput",
    "version": "0.5.2",
    "summary": "UITextField and UITextView replacement with animated hint and error message support. Highly customizable. Used in Jobandtalent iOS app",
    "description": "AnimatedTextInputnThis custom control can be used as a replacement for UITextField or UITextView. It comes with 5 different entry types: default, numeric, password, selection and multiline, but you can also extend its functionality by setting up your own TextInput.nThe animation consists on the placeholder becoming the hint. This control also allows for error state, showing an error message hint.",
    "homepage": "https://github.com/jobandtalent/AnimatedTextInput",
    "screenshots": "https://github.com/jobandtalent/AnimatedTextInput/raw/master/Assets/general.gif",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Victor Baro": "[email protected]"
    },
    "source": {
        "git": "https://github.com/jobandtalent/AnimatedTextInput.git",
        "tag": "0.5.2"
    },
    "social_media_url": "https://twitter.com/jobandtalentEng",
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "AnimatedTextInput/Classes/**/*",
    "resource_bundles": {
        "AnimatedTextInput": [
            "AnimatedTextInput/Assets/*.*"
        ]
    },
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This