A simple text field for building 'activation code text field' inspired by WhatsApp for iOS
If you're using Carthage, add the following dependency to your Cartfile
:
github "SandeepAggarwal/SACodedTextField"
If you're using CocoaPods, add the following dependency to your Podfile
:
pod 'SACodedTextField'
Check out the demo app for an example.
SACodedTextField
can be added to storyboard or instantiated programmatically:
ActivationCodeTextField* textField = [[ActivationCodeTextField alloc] initWithFrame:frame];
[self.view addSubview:textField];
A SACodedTextField
can be highly customised to set the custom placeholder string which can even include an emoji!.
textField.customPlaceholder = @"😀";
A SACodedTextField
can be customised to change the length of activation code/ OTP.
textField.maxCodeLength = 8;
A SACodedTextField
can also customised to adjust the length of spacing between the digits by adjusting the text field width.This will make the spacing between the digits to be adjusted automatically!
CGRect frame = textField.frame;
frame.size.width = 200.0;
textField.frame = frame;
If you are unsure about the width of the text field, don't worry!, just set the maxCodeLength
and get the minimum required width for the text field.
CGRect frame = textField.frame;
frame.size.width = [textField minWidthTextField];
textField.frame = frame;
A SACodedTextField
can have an optional delegate to receive callback.
// optional delegate
textField.activationCodeTFDelegate = self;
#pragma mark - <ActivationCodeTextFieldDelegate>
- (void)fillingCompleteForTextField:(ActivationCodeTextField *)textField
{
NSLog(@"text field filled completely");
}
- iOS 8 or higher.
- Automatic Reference Counting (ARC).
SACodedTextField is available under MIT license. See the LICENSE file for more info.