dimanche 28 décembre 2014

how to set limit of characters for user in UITextField or other in ios

When You ant to set character limit for a specific textField or other --


ex- for setting limit of mobile no. should not be more than 14 characters. then -


in your ViewController.m 1. import - 2. make - IBOutlet UITextField *txtMobileNo;

3. in ViewController.m - use this delegate method -




  • (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {


    NSString *newString = [txtMobileNo.text stringByReplacingCharactersInRange:range withString:string];


    return !([newString length] > 14 ); }




BOLD ITALIC words are changeable according to your need


Thats it :)




Aucun commentaire:

Enregistrer un commentaire