This library provides the ability to quickly implement the SMS input field. By default it supports the ability to automatically insert OneTimeCode into the field.
Features:
- Two default input fields
- The ability to make your own design
- Ability to animate an input indicator
- Ability to handle error state
CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate OTPTextField into your Xcode project using CocoaPods, specify it in your Podfile
:
pod 'SFOTPTextField', '~> 1.0.0'
In order to add a default field:
- Create instance of OTPTextField
- Add to your ViewController
- Implement handlers
In order to implement cutom field:
- Create your own pinView and implement protocol
PinContainer
- Create your own adapter class and implement protocol
OTPTextFieldData
- Add instance of OTPTextField to your ViewController
- Set your own custom configuration and implement handlers
func configureOtpField() {
let configuration = OTPFieldConfiguration(adapter: CustomFieldAdapter(),
keyboardType: .namePhonePad,
keyboardAppearance: .light,
autocorrectionType: .no,
allowedCharactersSet: .alphanumerics)
otpField.setConfiguration(configuration)
otpField.onBeginEditing = {
print("Handle Begin Editing")
}
otpField.onEndEditing = {
print("Handle End Editing")
}
otpField.onOTPEnter = { code in
print("Handle OTP entered action")
}
otpField.onTextChanged = { code in
print("Handle code changing")
}
}
OTPTextField is released under the MIT license. See LICENSE for details.