8

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?

2 Answers 2

24

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;
8

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.