Skip to content

Lightweight Pin Code Field library for iOS, written in Swift

License

Notifications You must be signed in to change notification settings

mohsinalimat/KAPinField

 
 

Repository files navigation

Language CocoaPods Compatible Carthage compatible Build Status Pod License

KAPinField

Lightweight Pin Code Field library for iOS, written in Swift. This library also plays well with the all new iOS 12 one time password autofill.

Basic use iOS12 autofill

Install

Using Cocoapods pod 'KAPinField'

Usage

Delegation

One simple delegate method called when the pin code is filled

protocol KAPinFieldDelegate {
  func pinfField(_ field: KAPinField, didFinishWith code: String)
}

Properties

pinField.token = "" // Default to "•"
pinField.numberOfCharacters = 5 // Default to 4
pinField.validCharacters = "0123456789+#?" // Default to "0123456789"
pinField.pinText = "123" // You can set part or all of the pin text

Styling

You can use the native defaultTextAttributes to style KAPinField. It's highly recommended to use one of iOS monospaced fonts to avoid weird text offset while editting the field.

let paragraph = NSMutableParagraphStyle()
paragraph.alignment = .center
let attributes : [NSAttributedString.Key : Any] = [
    .paragraphStyle : paragraph,
    .font : UIFont(name: "Menlo-Regular", size: 40)!,
    .kern : 14,
    .foregroundColor : UIColor.white]
pinField.defaultTextAttributes = attributes

Animation

KAPinField also provide some eye-candy for failure and success.

Success
field.animateSuccess(with: "👍") {
    print("Success")
}
Failure
field.animateFailure() {
   print("Failure")
}

About

Lightweight Pin Code Field library for iOS, written in Swift

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 93.3%
  • Ruby 6.7%