CocoaPods trunk is moving to be read-only. Read more on the blog, there are 11 months to go.

SGCodeTextField 0.1.4

SGCodeTextField 0.1.4

Maintained by Sergiu Grigoriev.




SGCodeTextField

Simple pin code textfield for iOS and tvOS. Customizable via Interface Builder or code.

Wiki

Installation

via CocoaPods

pod "SGCodeTextField"

via SwiftPackageManager

dependencies: [
    .package(url: "https://github.com/grigorievs/SGCodeTextField.git", .upToNextMajor(from: "0.1.3"))
]

Customisable properties

  • count
  • placeholder
  • autocapitalization
  • font
  • digitCornerRadius
  • digitBackgroundColor
  • digitBackgroundColorFocused
  • digitBackgroundColorEmpty
  • digitBorderColor
  • digitBorderColorFocused
  • digitBorderColorEmpty
  • digitBorderWidth
  • digitSpacing
  • textColor
  • textColorFocused
  • placeholderColor
  • keyboardType

Customizing via code:

self.codeTextField.count = 4

self.codeTextField.placeholder = "*"

self.codeTextField.textColorFocused = UIColor.brown

self.codeTextField.refreshUI()

Usage

Interface Builder

Drag and drop a 'UIView' on to the desired view and change class to 'SGCodeTextField'.

Code

let codeTextField = SGCodeTextField()

Getting text:

import SGCodeTextField

let value = self.codeTextField.text

Setting text:

self.codeTextField.text = "1234"

Observing text change events:

self.codeTextField.textChangeHandler = { text, completed in

    self.doneButton.isSelected = completed

    print(text ?? "")

}

Screenshots

Editing mode

Default mode

Other customisations

Editing mode