A UITextFieldhas a delegate method that should change characters in a range, this method basically asks the question: should the next character be added or removed? and from this you can dictate what you want. Here is a sample code.
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
BOOL shouldChangeCharacters = ( (textField.text.length + string.length) > 1 );
return shouldChangeCharacters;
}
, 1, , , ...
, , - , - , .
if (range.location == 0) {
NSString* firstCharacter = [string substringToIndex:1];
BOOL firstCharacterIsDesiredCharacter = [firstCharacter isEqualToString:@"#"];
if ( !firstCharacterIsDesiredCharacter ) {
NSString* symbolWithText = [NSString stringWithFormat:@"#%@",text];
[textView setText:symbolWithText];
return NO;
string = symbolWithText;
}
}
... . .. - , .
, , -, - 0 1. , 0, , . , . , UITextField #work, "work" "workwork", , - .
UITextField Reference