开发者

Cococa Touch - Verifying each character inputed

开发者 https://www.devze.com 2023-01-09 06:38 出处:网络
I want to have the user t开发者_运维技巧ype in something. And I want to verify each character inputed. How could I do this? I want it to be in real time. So as its typed its being verified and color c

I want to have the user t开发者_运维技巧ype in something. And I want to verify each character inputed. How could I do this? I want it to be in real time. So as its typed its being verified and color coded.

You could compare what I want to do to an programmers IDE how it checks the syntax as you type it.

Any help is appreciated!


Connect the UITextField delegate to the app delegate and do something like:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {

    if([string isEqual:@"b"]) {
        // User typed 'b'
        // Insert string with specific color
        // [...]
    } else {
        // User typed something else
        // Insert string without specific color
        textField.text = [textField.text stringByReplacingCharactersInRange:range withString:string];
    }
    return YES;

}
0

精彩评论

暂无评论...
验证码 换一张
取 消