### Installation Source: https://github.com/chililabs/chiotpfield/blob/master/README.md Instructions on how to install CHIOTPField using CocoaPods and Swift Package Manager. ```APIDOC ## Installation ### CocoaPods use [CocoaPods](https://cocoapods.org) with Podfile: ``` ruby pod 'CHIOTPField', '~> 0.1' # individual page control pod 'CHIOTPField/One' pod 'CHIOTPField/Two' pod 'CHIOTPField/Three' pod 'CHIOTPField/Four' ``` ### Swift Package Manager ``` swift dependencies: [ .package(url: "https://github.com/ChiliLabs/CHIOTPField.git", .upToNextMajor(from: "0.1")) ] ``` ``` -------------------------------- ### Install via CocoaPods Source: https://github.com/chililabs/chiotpfield/blob/master/README.md Add the library to your Podfile to manage dependencies. ```ruby pod 'CHIOTPField', '~> 0.1' # individual page control pod 'CHIOTPField/One' pod 'CHIOTPField/Two' pod 'CHIOTPField/Three' pod 'CHIOTPField/Four' ``` -------------------------------- ### Install via Swift Package Manager Source: https://github.com/chililabs/chiotpfield/blob/master/README.md Add the package dependency to your Package.swift file. ```swift dependencies: [ .package(url: "https://github.com/ChiliLabs/CHIOTPField.git", .upToNextMajor(from: "0.1")) ] ``` -------------------------------- ### Install CHIOTPField via CocoaPods Source: https://context7.com/chililabs/chiotpfield/llms.txt Add the library or specific field styles to your Podfile. ```ruby # Podfile # Install all field styles pod 'CHIOTPField', '~> 0.1' # Or install individual field styles pod 'CHIOTPField/One' pod 'CHIOTPField/Two' pod 'CHIOTPField/Three' pod 'CHIOTPField/Four' ``` -------------------------------- ### Install CHIOTPField via Swift Package Manager Source: https://context7.com/chililabs/chiotpfield/llms.txt Add the library as a dependency in your Package.swift file. ```swift // Package.swift dependencies: [ .package(url: "https://github.com/ChiliLabs/CHIOTPField.git", .upToNextMajor(from: "0.1")) ] ``` -------------------------------- ### Initialize OTP Field Programmatically Source: https://github.com/chililabs/chiotpfield/blob/master/README.md Create an instance of CHIOTPFieldOne and configure its basic properties. ```swift let field = CHIOTPFieldOne(frame: .init(x: 0, y: 0, width: 200, height: 60)) field.numberOfDigits = 4 field.cornerRadius = 4 ``` -------------------------------- ### Usage Source: https://github.com/chililabs/chiotpfield/blob/master/README.md How to use CHIOTPField in your project via Storyboards or code. ```APIDOC ## Usage ### 🎨 Storyboards Just drop UITextField and set its class to be one of CHIOTPField. ### 💻 Code ``` swift let field = CHIOTPFieldOne(frame: .init(x: 0, y: 0, width: 200, height: 60)) field.numberOfDigits = 4 field.cornerRadius = 4 ``` ### Text Color Just change the text color for textfield as you normaly do. ### Caret color Tint color is responsible for caret color. If you want to hide a caret, just set the color to clear. ``` -------------------------------- ### Implement CHIOTPFieldOne Programmatically Source: https://context7.com/chililabs/chiotpfield/llms.txt Configure and add the CHIOTPFieldOne bordered box style to a view controller. ```swift import UIKit class OTPViewController: UIViewController { private var otpField: CHIOTPFieldOne! override func viewDidLoad() { super.viewDidLoad() // Create OTP field programmatically otpField = CHIOTPFieldOne(frame: CGRect(x: 20, y: 100, width: 280, height: 60)) // Configure number of digit boxes otpField.numberOfDigits = 6 // Set spacing between boxes otpField.spacing = 8 // Configure box appearance otpField.boxBackgroundColor = .white otpField.borderColor = UIColor.lightGray otpField.cornerRadius = 8 // Configure active state shadow otpField.activeShadowColor = UIColor.systemBlue otpField.activeShadowOpacity = 0.5 // Optional placeholder for empty boxes otpField.boxPlaceholder = "0" otpField.boxPlaceholderColor = UIColor.lightGray.withAlphaComponent(0.5) // Set text appearance otpField.textColor = .black otpField.font = UIFont.systemFont(ofSize: 24, weight: .bold) // Enable secure entry for PIN codes otpField.isSecureTextEntry = false // Add target for text change events otpField.addTarget(self, action: #selector(otpDidChange), for: .editingChanged) view.addSubview(otpField) } @objc func otpDidChange() { if let code = otpField.text, code.count == 6 { print("OTP entered: \(code)") verifyOTP(code: code) } } func verifyOTP(code: String) { // Handle OTP verification } } ``` -------------------------------- ### Configure OTPFieldOne Properties Source: https://github.com/chililabs/chiotpfield/blob/master/README.md Available configuration properties for the OTPFieldOne component. ```swift var numberOfDigits: Int // number of boxes for digits var spacing: Int // spacing between digits var boxBackgroundColor: UIColor // background color of the box in normal state var borderColor: UIColor // border color of the box in normal state var cornerRadius: CGFloat // corner radius of the box var activeShadowColor: UIColor? // shadow color of the box in active state var activeShadowOpacity: CGFloat // shadow opacity of the box in active state var boxPlaceholder: String? // placeholder text var boxPlaceholderColor: UIColor? // placeholder text color ``` -------------------------------- ### Configure CHIOTPFieldThree with Underline and Dot Style Source: https://context7.com/chililabs/chiotpfield/llms.txt Implement CHIOTPFieldThree for a minimalist PIN entry with a bottom underline and dot representation for digits. Customize dot size, underline dimensions, and text/caret colors. ```swift import UIKit class PinEntryViewController: UIViewController { private var pinField: CHIOTPFieldThree! override func viewDidLoad() { super.viewDidLoad() pinField = CHIOTPFieldThree(frame: CGRect(x: 40, y: 200, width: 240, height: 50)) // 4-digit PIN configuration pinField.numberOfDigits = 4 pinField.spacing = 20 // Background color pinField.boxBackgroundColor = .clear // Underline configuration pinField.borderHeight = 3 pinField.borderCornerRadius = 1.5 // Dot appearance when digit is entered pinField.dotRadius = 10 // Text color affects both dot and underline color pinField.textColor = UIColor.systemIndigo pinField.tintColor = UIColor.systemIndigo // Caret color // Hide caret by setting clear tint // pinField.tintColor = .clear pinField.addTarget(self, action: #selector(pinChanged), for: .editingChanged) view.addSubview(pinField) } @objc func pinChanged() { if let pin = pinField.text, pin.count == 4 { authenticateWithPIN(pin) } } func authenticateWithPIN(_ pin: String) { print("Authenticating with PIN") } // Programmatically set text func prefillPIN() { pinField.text = "1234" } // Clear the field func clearPIN() { pinField.text = "" } } ``` -------------------------------- ### Integrate CHIOTPField with Storyboard Source: https://context7.com/chililabs/chiotpfield/llms.txt Demonstrates connecting an OTP field from a Storyboard and configuring properties programmatically or via the Attributes Inspector. ```swift import UIKit class StoryboardOTPViewController: UIViewController { // Connect from Storyboard - set class to CHIOTPFieldOne in Identity Inspector @IBOutlet weak var otpField: CHIOTPFieldOne! override func viewDidLoad() { super.viewDidLoad() // Properties can also be configured in Storyboard's Attributes Inspector: // - Number Of Digits: 6 // - Spacing: 8 // - Box Background Color: White // - Border Color: Light Gray // - Corner Radius: 8 // - Active Shadow Color: System Blue // - Active Shadow Opacity: 0.4 // - Box Placeholder: (empty or custom) // - Box Placeholder Color: Light Gray // Add programmatic handlers otpField.addTarget(self, action: #selector(otpEntered), for: .editingChanged) } @objc func otpEntered() { if let code = otpField.text, code.count == otpField.numberOfDigits { handleOTPSubmission(code) } } func handleOTPSubmission(_ code: String) { // Verify the OTP code } // Access individual digit labels func highlightErrorDigits() { otpField.labels.forEach { label in label.layer.borderColor = UIColor.systemRed.cgColor } } } ``` -------------------------------- ### Implement CHIOTPFieldFour with Underline Style Source: https://context7.com/chililabs/chiotpfield/llms.txt Configures an OTP field with an underline-only appearance and handles input completion via target-action. ```swift import UIKit class SMSCodeViewController: UIViewController { private var smsField: CHIOTPFieldFour! override func viewDidLoad() { super.viewDidLoad() smsField = CHIOTPFieldFour(frame: CGRect(x: 30, y: 180, width: 320, height: 60)) // 6-digit SMS code smsField.numberOfDigits = 6 smsField.spacing = 10 // Box styling smsField.boxBackgroundColor = .clear smsField.cornerRadius = 0 // Bottom border configuration smsField.borderHeight = 2 smsField.borderColor = UIColor.systemGray3 // Text appearance smsField.textColor = .label smsField.font = UIFont.systemFont(ofSize: 32, weight: .medium) // Set caret color smsField.tintColor = UIColor.systemBlue smsField.addTarget(self, action: #selector(smsCodeChanged), for: .editingChanged) view.addSubview(smsField) // Auto-focus the field smsField.becomeFirstResponder() } @objc func smsCodeChanged() { guard let code = smsField.text else { return } if code.count == smsField.numberOfDigits { submitSMSCode(code) } } func submitSMSCode(_ code: String) { smsField.resignFirstResponder() print("Submitting SMS code: \(code)") } } ``` -------------------------------- ### Configure OTPFieldTwo Properties Source: https://github.com/chililabs/chiotpfield/blob/master/README.md Available configuration properties for the OTPFieldTwo component. ```swift var numberOfDigits: Int // number of boxes for digits var spacing: Int // spacing between digits var cornerRadius: CGFloat // corner radius of the box var boxBackgroundColor: UIColor // background color of the box in normal state var activeBoxBackgroundColor: UIColor // background color of the box in active state var filledBoxBackgroundColor: UIColor // background color of the box if a text is entered var borderColor: UIColor // border color of the box in normal state var activeBorderColor: UIColor? // border color of the box in active var filledBorderColor: UIColor? // border color of the box if a text is entered var boxPlaceholder: String? // placeholder text var boxPlaceholderColor: UIColor? // placeholder text color ``` -------------------------------- ### Configure OTPFieldFour Properties Source: https://github.com/chililabs/chiotpfield/blob/master/README.md Available configuration properties for the OTPFieldFour component. ```swift var numberOfDigits: Int // number of boxes for digits var spacing: Int // spacing between digits var boxBackgroundColor: UIColor // background color of the box in normal state var borderHeight: CGFloat / /bottom border height var borderColor: CGFloat // bottom border color var cornerRadius: CGFloat // corner radius of the box ``` -------------------------------- ### Configure OTPFieldThree Properties Source: https://github.com/chililabs/chiotpfield/blob/master/README.md Available configuration properties for the OTPFieldThree component. ```swift var numberOfDigits: Int // number of boxes for digits var spacing: Int // spacing between digits var boxBackgroundColor: UIColor // background color of the box in normal state var borderHeight: CGFloat / /bottom border height var borderCornerRadius: CGFloat // bottom border radius var dotRadius: CGFloat // dot radius when text is entered ``` -------------------------------- ### Configure CHIOTPFieldTwo with Multi-State Backgrounds Source: https://context7.com/chililabs/chiotpfield/llms.txt Set up CHIOTPFieldTwo with distinct background and border colors for normal, active, and filled states. Configure digit count, spacing, corner radius, placeholder, and text appearance. ```swift import UIKit class VerificationViewController: UIViewController { private var codeField: CHIOTPFieldTwo! override func viewDidLoad() { super.viewDidLoad() codeField = CHIOTPFieldTwo(frame: CGRect(x: 20, y: 150, width: 300, height: 55)) // Configure digit count and spacing codeField.numberOfDigits = 4 codeField.spacing = 12 // Normal state - gray background with border codeField.boxBackgroundColor = UIColor.systemGray6 codeField.borderColor = UIColor.systemGray4 // Active state - white background with blue border codeField.activeBoxBackgroundColor = .white codeField.activeBorderColor = UIColor.systemBlue // Filled state - light blue background with blue border codeField.filledBoxBackgroundColor = UIColor.systemBlue.withAlphaComponent(0.1) codeField.filledBorderColor = UIColor.systemBlue // Box styling codeField.cornerRadius = 12 // Placeholder configuration codeField.boxPlaceholder = "-" codeField.boxPlaceholderColor = UIColor.systemGray3 // Text appearance codeField.textColor = UIColor.systemBlue codeField.font = UIFont.monospacedDigitSystemFont(ofSize: 28, weight: .semibold) // Add completion handler codeField.addTarget(self, action: #selector(codeEntered), for: .editingChanged) view.addSubview(codeField) } @objc func codeEntered() { guard let text = codeField.text else { return } // Check if all digits entered if text.count == codeField.numberOfDigits { // Dismiss keyboard and process code codeField.resignFirstResponder() processVerificationCode(text) } } func processVerificationCode(_ code: String) { print("Processing verification code: \(code)") } } ``` -------------------------------- ### OTPFieldOne Properties Source: https://github.com/chililabs/chiotpfield/blob/master/README.md Properties available for OTPFieldOne. ```APIDOC ### OTPFieldOne ``` swift var numberOfDigits: Int // number of boxes for digits var spacing: Int // spacing between digits var boxBackgroundColor: UIColor // background color of the box in normal state var borderColor: UIColor // border color of the box in normal state var cornerRadius: CGFloat // corner radius of the box var activeShadowColor: UIColor? // shadow color of the box in active state var activeShadowOpacity: CGFloat // shadow opacity of the box in active state var boxPlaceholder: String? // placeholder text var boxPlaceholderColor: UIColor? // placeholder text color ``` ``` -------------------------------- ### OTPFieldTwo Properties Source: https://github.com/chililabs/chiotpfield/blob/master/README.md Properties available for OTPFieldTwo. ```APIDOC ### OTPFieldTwo ``` swift var numberOfDigits: Int // number of boxes for digits var spacing: Int // spacing between digits var cornerRadius: CGFloat // corner radius of the box var boxBackgroundColor: UIColor // background color of the box in normal state var activeBoxBackgroundColor: UIColor // background color of the box in active state var filledBoxBackgroundColor: UIColor // background color of the box if a text is entered var borderColor: UIColor // border color of the box in normal state var activeBorderColor: UIColor? // border color of the box in active var filledBorderColor: UIColor? // border color of the box if a text is entered var boxPlaceholder: String? // placeholder text var boxPlaceholderColor: UIColor? // placeholder text color ``` ``` -------------------------------- ### OTPFieldThree Properties Source: https://github.com/chililabs/chiotpfield/blob/master/README.md Properties available for OTPFieldThree. ```APIDOC ### OTPFieldThree ``` swift var numberOfDigits: Int // number of boxes for digits var spacing: Int // spacing between digits var boxBackgroundColor: UIColor // background color of the box in normal state var borderHeight: CGFloat / /bottom border height var borderCornerRadius: CGFloat // bottom border radius var dotRadius: CGFloat // dot radius when text is entered ``` ``` -------------------------------- ### OTPFieldFour Properties Source: https://github.com/chililabs/chiotpfield/blob/master/README.md Properties available for OTPFieldFour. ```APIDOC ### OTPFieldFour ``` swift var numberOfDigits: Int // number of boxes for digits var spacing: Int // spacing between digits var boxBackgroundColor: UIColor // background color of the box in normal state var borderHeight: CGFloat / /bottom border height var borderColor: CGFloat // bottom border color var cornerRadius: CGFloat // corner radius of the box ``` ``` -------------------------------- ### Access and Manipulate Individual Digit Labels Source: https://context7.com/chililabs/chiotpfield/llms.txt Provides methods to inspect digit states, perform custom animations, and manipulate the field text programmatically. ```swift import UIKit class CustomOTPViewController: UIViewController { var otpField: CHIOTPFieldOne! override func viewDidLoad() { super.viewDidLoad() otpField = CHIOTPFieldOne(frame: CGRect(x: 20, y: 100, width: 280, height: 60)) otpField.numberOfDigits = 4 view.addSubview(otpField) } // Access all digit labels func getLabels() -> [CHIOTPFieldOneLabel] { return otpField.labels } // Check each digit's state func inspectDigitStates() { for (index, label) in otpField.labels.enumerated() { print("Digit \(index): text=\(label.text ?? "nil"), active=\(label.active)") } } // Custom error animation func showErrorState() { UIView.animate(withDuration: 0.1, animations: { self.otpField.transform = CGAffineTransform(translationX: 10, y: 0) }) { _ in UIView.animate(withDuration: 0.1, animations: { self.otpField.transform = CGAffineTransform(translationX: -10, y: 0) }) { _ in UIView.animate(withDuration: 0.1) { self.otpField.transform = .identity } } } } // Programmatic text manipulation func setCode(_ code: String) { otpField.text = code } func clearCode() { otpField.text = "" } func getEnteredCode() -> String? { return otpField.text } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.