CocoaPods trunk is moving to be read-only. Read more on the blog, there are 13 months to go.
| TestsTested | ✗ |
| LangLanguage | Obj-CObjective C |
| License | MIT |
| ReleasedLast Release | May 2016 |
Maintained by Dmitry Nesterenko.
CHRTextFieldFormatter allows you to apply an input mask to a UITextField instance.
UITextField subclassing.CHRTextMask interface to allow custom text masking algorithm implementation.NSFormatter.There are two kind of masks available:
CHRPhoneNumberMask to apply cellular phone number mask.CHRCardNumberMask to apply credit card number mask.Phone number mask can be configured to have non-deletable prefix. For example:
CHRPhoneNumberMask *mask = [CHRPhoneNumberMask new];
mask.prefix = @"+7";Drag *.h and *.m files to your project.
- (void)viewDidLoad {
[super viewDidLoad];
self.phoneNumberFormatter = [[CHRTextFieldFormatter alloc] initWithTextField:self.phoneNumberTextField mask:[CHRPhoneNumberMask new]];
self.cardNumberFormatter = [[CHRTextFieldFormatter alloc] initWithTextField:self.cardNumberTextField mask:[CHRCardNumberMask new]];
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if (textField == self.phoneNumberTextField) {
return [self.phoneNumberFormatter textField:textField shouldChangeCharactersInRange:range replacementString:string];
} else if (textField == self.cardNumberTextField) {
return [self.cardNumberFormatter textField:textField shouldChangeCharactersInRange:range replacementString:string];
} else {
return YES;
}
}
Run the example project to see the demo.