0

In iOS 5 I wish to have a text field for a user's name. It would be good to have a keyboard that displays only letters and numbers (and maybe 1 punctuation character, or maybe just letters). Perhaps characters not allowed to be used could be greyed out.

Is this functionality possible? Or is there a better way to do it?

Thank you :-)

Jon Cox
  • 10,622
  • 22
  • 78
  • 123
  • Check this http://stackoverflow.com/questions/6954382/uitextfield-should-have-only-positive-number/6954599#6954599 – beryllium Nov 22 '11 at 20:56

2 Answers2

0

You have a

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

method in UITextFieldDelegate protocol. If you'll return NO the change will not be accepted thus leaving text as it was before last input. So basically you just need to implement your acceptance logic inside.

Hope it helps.

Alex Cio
  • 6,014
  • 5
  • 44
  • 74
Ariel
  • 2,430
  • 1
  • 17
  • 20
0

You can define a custom input view (i.e. a custom keyboard) by using the inputView property. More info on the property: http://developer.apple.com/library/ios/documentation/uikit/reference/UIResponder_Class/Reference/Reference.html#//apple_ref/occ/instp/UIResponder/inputView