0

Is there a UIKeyboard that gives out just letters and nothing else? I tried out the alphabet one but it gives out numbers.

woz
  • 10,888
  • 3
  • 34
  • 64
moo
  • 37
  • 1
  • 4
  • 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 Answers1

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];
}
Community
  • 1
  • 1
woz
  • 10,888
  • 3
  • 34
  • 64