Skip to content

Simple pin code textfield. Customizable via Interface Builder or code.

License

Notifications You must be signed in to change notification settings

grigorievs/SGCodeTextField

Repository files navigation

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.4"))
]

Customisable properties

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

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