Skip to content
Simple pin code textfield. Customizable via Interface Builder or code.
Swift Objective-C Ruby
Branch: master
Clone or download
Latest commit 69b534a Sep 16, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Demo/SGCodeTextField-Demo Source files Sep 4, 2019
SGCodeTextField.xcodeproj Source files Sep 4, 2019
SGCodeTextField fix a crash when setting the count property with a negative value and… Sep 14, 2019
LICENSE Update LICENSE Sep 4, 2019
README.md
SGCodeTextField.podspec

README.md

SGCodeTextField

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

Wiki

Installation

via CocoaPods

pod "SGCodeTextField"

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

You can’t perform that action at this time.