Latest 2.0.0
Homepage https://github.com/kirualex/KAPinField
License MIT
Platforms ios 10.3
Authors

Language
CocoaPods Compatible
Build Status
Pod License

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.

KAPinField KAPinField
Basic use iOS12 autofill

Install

With Cocoapods
pod 'KAPinField'

Usage

import KAPinField

class MyController : UIVIewController {
  ...
}

Storyboard

You can add an UITextField directly in your Storyboard scene and declare it as KAPinField. It will automagically become a pin field. You can then customize it from the inspector view to suit your needs.

Delegation

Don’t forget to set the delegate likeso :


@IBOutlet var pinField: KAPinField!

override func viewDidLoad() {
        super.viewDidLoad()
        pinField.ka_delegate = self
        ...
}

One simple method will be called on your delegate

extension MyController : KAPinFieldDelegate {
  func ka_pinField(_ field: KAPinField, didFinishWith code: String) {
    print("didFinishWith : (code)")
  }
}

Properties

All the properties you need for KAPinField are previxed with ka_.

Logic
pinField.ka_token = "-" // Default to "•"
pinField.ka_numberOfCharacters = 5 // Default to 4
pinField.ka_validCharacters = "0123456789+#?" // Default to only numbers, "0123456789"
pinField.ka_text = "123" // You can set part or all of the text
Styling
pinField.ka_textColor = UIColor.white.withAlphaComponent(1.0) // Default to nib color or black if initialized programmatically.
pinField.ka_tokenColor = UIColor.black.withAlphaComponent(0.3) // token color, default to text color
pinField.ka_font = .menloBold(40) // Default to KA_MonospacedFont.menlo(40)
pinField.ka_kerning = 20 // Space between characters, default to 16

Font

A monospaced font is highly recommended in order to avoid horizontal offsetting during typing. For this purpose, a handy helper is available to allow you to access native iOS monospaced fonts.
To use it, just set ka_font with a enum value from KA_MonospacedFont.
You can of course still use your own font by setting the default font property on KAPinField.

Animation

KAPinField also provide some eye-candy for failure and success. As for properties, those methods are prefixed with ka_.

Success
field.ka_animateSuccess(with: "👍") {
    print("Success")
}
Failure
field.ka_animateFailure() {
   print("Failure")
}

Latest podspec

{
    "name": "KAPinField",
    "version": "2.0.0",
    "summary": "Lightweight Pin Code Field library for iOS, written in Swift",
    "homepage": "https://github.com/kirualex/KAPinField",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Alexis Creuzot": "[email protected]"
    },
    "source": {
        "git": "https://github.com/kirualex/KAPinField.git",
        "tag": "2.0.0"
    },
    "platforms": {
        "ios": "10.3"
    },
    "source_files": "**/KAPinField.swift"
}

Pin It on Pinterest

Share This