There are some application in which validated text fields gets highlighted red, when the user enters wrong information into it.
I want to use this validation and highlighting technique on the iPhone too. How can I do that?
Change the border color of a TextField by using QuartzCore
#import <QuartzCore/QuartzCore.h>
[...]
textField.layer.borderWidth = 1.0f;
textField.layer.borderColor = [[UIColor redColor] CGColor];
with rounded corners
textField.layer.cornerRadius = 5;
textField.clipsToBounds = YES;
you can validate the text by setting the UITextField's delegate to your controller then do something like :
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range {
[self validateInput]; // Your method to check what the user is writting
return YES;
}
And in your "validateInput", change the background image if the validation fails.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With