frank0ch0a
frank0ch0a

Reputation: 43

Changing letter typed by Keyboard by other letter and show it in UITextfield

I want to know if possible, to change the letter typed by keyboard before to display in a UITexfield (To create a secret code) and then in other UITextfield decodify it.

i. e.

I type " a " and then UITextfield Will display "d" and other UITexfield to read and invert "d" to " a"

Upvotes: 0

Views: 95

Answers (1)

BergP
BergP

Reputation: 3545

Yes, use method – textField:shouldChangeCharactersInRange:replacementString: in UITextFieldDelegate.

f.e.

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSString* encodedString = [self encode:string];
textField.text = [textField.text stringByReplacingCharactersInRange:range withString:
        encodedString];
self.decodedTextField.text = [self.decodedTextField.text stringByReplacingCharactersInRange:range withString:string];
return NO;                  
}

it is just example, you should implement replacement more careful.

Upvotes: 2

Related Questions