Skip to content

A simple text field for building 'activation code/ OTP text field' inspired by WhatsApp for iOS

License

Notifications You must be signed in to change notification settings

SandeepAggarwal/SACodedTextField

Repository files navigation

SACodedTextField

Build Status codecov Platform Carthage compatible CocoaPods Compatible Twitter URL

A simple text field for building 'activation code text field' inspired by WhatsApp for iOS

Preview

Emoji

gif

Default

gif2

Installation

Carthage

If you're using Carthage, add the following dependency to your Cartfile:

github "SandeepAggarwal/SACodedTextField"

CocoaPods

If you're using CocoaPods, add the following dependency to your Podfile:

pod 'SACodedTextField'

Usage

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");
}

Requirements

  • iOS 8 or higher.
  • Automatic Reference Counting (ARC).

License

SACodedTextField is available under MIT license. See the LICENSE file for more info.