Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validation on text field: highlighted red border, iPhone

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?

like image 860
Mann Avatar asked Aug 19 '11 16:08

Mann


2 Answers

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;
like image 130
Martin Stolz Avatar answered Nov 15 '22 21:11

Martin Stolz


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.

like image 26
Zoleas Avatar answered Nov 15 '22 21:11

Zoleas