How can I set the maximum amount of characters in a UITextField
on the iPhone SDK when I load up a UIView
?
I created this UITextFieldLimit subclass:
Grab the UITextFieldLimit.h
and UITextFieldLimit.m
from this GitHub repository:
https://github.com/JonathanGurebo/UITextFieldLimit
and begin to test!
Mark your storyboard-created UITextField and link it to my subclass using the Identity Inspector:
Then you can link it to an IBOutlet and set the limit(default is 10).
Your ViewController.h file should contain: (if you wan't to modify the setting, like the limit)
#import "UITextFieldLimit.h"
/.../
@property (weak, nonatomic) IBOutlet UITextFieldLimit *textFieldLimit; // <--Your IBOutlet
Your ViewController.m file should @synthesize textFieldLimit
.
Set the text length limit in your ViewController.m file:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[textFieldLimit setLimit:25];// <-- and you won't be able to put more than 25 characters in the TextField.
}
Hope the class helps you. Good luck!