ios - UITextField with a text length counter -


well title says mostly:

is there ready go uitextfield component out there can take number (maximum text length) in label? cool if number can displayed.

is there component out there?

what have:

  1. limit input custom text length
  2. number of left character gets displayed inside textfield
  3. paste prevention

i created this uitextfieldlimit subclass:

  • multiple textfields supported
  • set text length limit
  • paste prevention
  • displays label of left characters inside textfield, hidden when stop editing.
  • delegate
  • shake animation when no characters left.

grab uitextfieldlimit.h , uitextfieldlimit.m github repository:

https://github.com/jonathangurebo/uitextfieldlimit

and begin test!

mark storyboard-created uitextfield , link subclass using identity inspector:

identity inspector

then can link iboutlet , set limit(default 10).


your viewcontroller.h file should contain: (if wan't modify setting, limit)

#import "uitextfieldlimit.h"  /.../  @property (weak, nonatomic) iboutlet uitextfieldlimit *textfieldlimit; // <--your iboutlet 

your viewcontroller.m file should @synthesize textfieldlimit.


set text length limit in viewcontroller.m file:

- (void)viewdidload {     [super viewdidload]; // additional setup after loading view, typically nib.      [textfieldlimit setlimit:25];// <-- , won't able put more 25 characters in textfield. } 

hope class helps you. luck!


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -