Coder Social home page Coder Social logo

trendingtechnology / underlinetextfield Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mohammadalijf/underlinetextfield

0.0 3.0 0.0 5.72 MB

Simple UITextfield Subclass with state

License: MIT License

Swift 96.99% Ruby 2.15% Objective-C 0.86%

underlinetextfield's Introduction

Build Status Carthage Compatible CocoaPods

UnderLineTextField

Simple UITextfield Subclass with state

demo

Installation

Cocoapods

You can use cocoapods to add UnderLineTextField to your project

target 'MyApp' do
  pod 'UnderLineTextField', '~> 2.0'
end

Carthage

You can use Carthage to add UnderLineTextField to your project

To integrate UnderLineTextField into your Xcode project using Carthage, specify it in your 'Cartfile':

github "mohammadalijf/UnderLineTextField"

Run carthage update to build the framework and drag the built UnderLineTextField.framework into your Xcode project.

xcode does not support 'IBDesignable' or 'IBInspecatable' on cocoa frameworks. to work around for carthage users. created simple 'UnderLineTextFieldCarthage.swift' file. it is a wrapper around 'UnderLineTextfield' which can be used in projects for supporting 'IBDesignable' and 'IBInspecatable'. just simply drop 'UnderLineTextFieldCarthage.swift' in your project and use this class instead of 'UnderLineTextfield'.

How It Works

UnderLineTextField

each textfield have four state

  • inactive

    when textfield have no errors or warnings and is resigned from first responder

  • active

    when textfield become first responder

  • warning

    when you want show warnings to user

  • error

    when you want show error to user

by default textfield have .inactive state

textfield have diffrent kind of UnderLineTextFieldValidateType. each time tells textfield when call validate().

  • onFly

    as soon as textfield value changes

  • afterEdit

    as soon as textfield didEndEditing

  • onCommit

    manualy gets validate by user

  • always

    alway validate textfield. when become beginEditing, when value changes, when didEndEditing

by default value is .afterEdit

you can change validation type by setting validationType

 underLineTextField.validationType = .always

you can ask textfield to validate user input by calling

underLineTextField.validate()

UnderLineTextFieldDelegate

Also you have UnderLineTextFieldDelegate to help you with your textfield. when a class confirm to UnderLineTextFieldDelegate protocol, it also confirms to UITextFieldDelegate. so you have both delegate methods on hand.

  • textFieldValidate

this func is called whenever you ask the textfield to validate() user input. you usually want to set warning or error state in here.

func textFieldValidate(underLineTextField: UnderLineTextField) throws

you can either throw warrning or errors

func textFieldValidate(underLineTextField: UnderLineTextField) throws {
    throw UnderLineTextFieldErrors
                    .error(message: "error message")
    // or
    throw UnderLineTextFieldErrors
                    .warning(message: "warning message")
}
  • textFieldTextChanged

this func is called when text changes. or clear button is used.

func textFieldTextChanged(underLineTextField: UnderLineTextField)

underlinetextfield's People

Contributors

lekonstantine avatar mohammadalijf avatar

Watchers

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