Giter VIP home page Giter VIP logo

beautifultextfield's Introduction

BeautifulTextField

Version License Platform

About

BeautifulTextField is just a beautiful UITextField. Easy to customize! Easy to use! Try it now!

Example

Example Gif

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Inside Interface Builder (storyboard / XIB) set borderStyle to None and setup custom height of textField ~ 40pt~50pt (depends on fontSize and placeholderFontScale)

Customize

Use default property to setup textField

// Readonly views
var borderView: UIView!
var bottomBorderView: UIView!
var placeholderLabel: UILabel!

// Border
var borderInactiveColor: UIColor = .lightGray
var borderActiveColor: UIColor = .red
var borderWidth: CGFloat = 2.0

// Placeholder
var placeholderFontScale: CGFloat = 0.7
var placeholderColor: UIColor = .black
var placeholder: String  // Setup placeholder inside Inteface Builder or right inside code!

// Error
var errorColor: UIColor = .red
var errorValidationHandler: (String) -> (String?)
var isValid: Bool  // (readonly) Anytime you could check textField validation status

Use your own validator

emailTextField.errorValidationHandler = { text in
    let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}"

    let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx)
    let match = emailTest.evaluate(with: text)
    return (match ? "Invalid email" : nil)
}

Setup custom textColor animation! (or whatever you want!)

open override func configureTextField(forTextFieldStateType textFieldStateType: BaseBeautifulTextField.TextFieldStateType, forTextStateType textStateType: BaseBeautifulTextField.TextStateType, animated: Bool, animations: (() -> ())?, completion: ((Bool) -> ())?) {
    super.configureTextField(forTextFieldStateType: textFieldStateType, forTextStateType: textStateType, animated: animated, animations: { 
        switch textFieldStateType {
        case .display:
            self.textColor = self.textColor?.withAlphaComponent(0.6)

        case .entry:
            self.textColor = self.textColor?.withAlphaComponent(1.0)
        }
    }) { (finished) in
        // ...
    }
}

Installation

BeautifulTextField is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "BeautifulTextField"

Author

Dmitry Utmanov, [email protected]

License

BeautifulTextField is available under the MIT license. See the LICENSE file for more info.

beautifultextfield's People

Contributors

yuop7 avatar

Stargazers

Yura Savelyev avatar  avatar Kirill Khudyakov avatar Yury Bogdanov avatar Aigerim Janaliyeva avatar Igor Galay avatar Carabineiro avatar

Watchers

James Cloos avatar Dmitrii Cooler avatar Carabineiro 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.