Is there a UIKeyboard
that gives out just letters and nothing else? I tried out the alphabet one but it gives out numbers.
Asked
Active
Viewed 670 times
0
-
Basically a duplicate: http://stackoverflow.com/questions/8233581/ios-text-field-show-only-letters-numbers-and-some-punctuation-on-the-keyboard – woz Nov 20 '12 at 18:50
1 Answers
1
You can't get a letters-only keyboard without subclassing UIKeyboard
to create your own from scratch; but you can reject characters you don't want using a UITextFieldDelegate
.
If string
is anything other than a letter, return NO
for this function:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;
Here is an adaption of the answer here for your situation:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"] invertedSet];
NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
return [string isEqualToString:filtered];
}