GithubHelp home page GithubHelp logo

mahipal-codzgarage / svpinview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xornorik/svpinview

0.0 1.0 0.0 5.13 MB

SVPinView is a light-weight customisable library used for accepting pin numbers or one-time passwords.

License: MIT License

Ruby 3.94% Swift 94.15% Objective-C 1.91%

svpinview's Introduction

SVPinView

SVPinView is a light-weight customisable library used for accepting pin numbers or one-time passwords.

Swift 4 compatible CocoaPods compatible Platform iOS License: MIT

demo

Getting Started

An example project is included for demonstrating the functionality of SVPinView.

Installation

CocoaPods

Add the following line to your Podfile:

pod 'SVPinView', '~> 1.0'

Then run the following in the same directory as your Podfile:

pod install

Manual

Clone the repo and drag files from SVPinView/Source folder into your Xcode project.

Usage

Storyboard

IBInspectables

Code

pinView.pinLength = 5
pinView.secureCharacter = "\u{25CF}"
pinView.interSpace = 5
pinView.textColor = UIColor.black
pinView.shouldSecureText = true
pinView.style = .box

pinView.borderLineColor = UIColor.black
pinView.activeBorderLineColor = UIColor.lightGray
pinView.borderLineThickness = 1
pinView.activeBorderLineThickness = 3

pinView.font = UIFont.systemFont(ofSize: 15)
pinView.keyboardType = .phonePad
pinView.pinIinputAccessoryView = UIView()
pinView.placeholder = "******"
pinView.becomeFirstResponderAtIndex = 0

The becomeFirstResponderAtIndex property sets the pinField at the specified index as the first responder. The isContentTypeOneTimeCode property sets the contentType of the first pinField to .oneTimeCode to leverage the iOS 12 feature where the passcode is directly fetched from the messages.

Styles

enum SVPinViewStyle : Int {
case none = 0
case underline
case box
}

There are two inbuilt styes; underline & box. However, the fieldBackgroundColor & fieldCornerRadius properties along with activeFieldBackgroundColor & activeCornerRadius properties can be used to create custom styles.

pinView.style = .none
pinView.fieldBackgroundColor = UIColor.white
pinView.fieldCornerRadius = 0

Methods

  • getPin(): Returns the entered pin as a String. If the method is called when the pin entry is incomplete, it returns an empty String for validation.
  • pastePin(): Takes a String as an argument and enters it into the pinView. Useful for showing default values or for pasting from clipboard. Long-press on the pin field will also allow pasting from the clipboard.
  • clearPin(): Clears the entered pin.

Callbacks

  • didFinishCallback: Gets executed after the entire pin has been entered. This is useful when a network call has to be made or for navigating to a different ViewController after the pin has been entered.
  • didChangeCallback: Gets executed when any of the pinFields have been changed. This gives additional control to the parent VC - Eg: if a submit button has to be enabled/disabled based on the pin validation.
pinView.didFinishCallback = { pin in
print("The pin entered is \(pin)")
}
pinView.didChangeCallback = { pin in
submitButton.isEnabled = isValid(pin)
}

Requirements

  • iOS 9.0 +
  • Xcode 8.0 +

License

SVPinView is available under the MIT license. See LICENSE for details.

svpinview's People

Contributors

xornorik avatar dangthaison91 avatar logicsb avatar

Watchers

James Cloos 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.