Swiftpack.co - kirualex/KAPinField as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Lightweight, highly customizable Pin Code Field library for iOS, written in Swift
.package(url: "https://github.com/kirualex/KAPinField.git", from: "5.0.2")

Platform Language CocoaPods Compatible Carthage 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.



With Cocoapods pod 'KAPinField'


import KAPinField

class MyController : UIVIewController {


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.


Don't forget to set the delegate likeso :

@IBOutlet var pinField: KAPinField!

override func viewDidLoad() {
        pinField.properties.delegate = self

One simple method will be called on your delegate

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


All the logic properties are available in the KAPinFieldProperties struct named properties.

pinField.properties.token = "-" // Default to "•"
pinField.properties.numberOfCharacters = 5 // Default to 4
pinField.properties.validCharacters = "0123456789+#?" // Default to only numbers, "0123456789"
pinField.properties.text = "123" // You can set part or all of the text
pinField.properties.animateFocus = true // Animate the currently focused token
pinField.properties.isSecure = false // Secure pinField will hide actual input
pinField.properties.secureToken = "*" // Token used to hide actual character input when using isSecure = true
pinField.properties.isUppercased = false // You can set this to convert input to uppercased.

All the styling can be done via the KAPinFieldAppearance struct named appearance.

pinField.appearance.font = .menloBold(40) // Default to appearance.MonospacedFont.menlo(40)
pinField.appearance.kerning = 20 // Space between characters, default to 16
pinField.appearance.textColor = UIColor.white.withAlphaComponent(1.0) // Default to nib color or black if initialized programmatically.
pinField.appearance.tokenColor = UIColor.black.withAlphaComponent(0.3) // token color, default to text color
pinField.appearance.tokenFocusColor = UIColor.black.withAlphaComponent(0.3)  // token focus color, default to token color
pinField.appearance.backOffset = 8 // Backviews spacing between each other
pinField.appearance.backColor = UIColor.clear
pinField.appearance.backBorderWidth = 1
pinField.appearance.backBorderColor = UIColor.white.withAlphaComponent(0.2)
pinField.appearance.backCornerRadius = 4
pinField.appearance.backFocusColor = UIColor.clear
pinField.appearance.backBorderFocusColor = UIColor.white.withAlphaComponent(0.8)
pinField.appearance.backActiveColor = UIColor.clear
pinField.appearance.backBorderActiveColor = UIColor.white
pinField.appearance.keyboardType = UIKeyboardType.numberPad // Specify keyboard type


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 appearance.font with a enum value from appearance.MonospacedFont. You can of course still use your own font by setting the default font property on KAPinField.


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

pinfield.animateSuccess(with: "👍") {
pinfield.animateFailure() {


Stars: 165
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

1 week ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics