Quick iPhone SDK Observation

 

I spent most of last evening and some of this morning sifting through the various documentation and classes for the UIKit framework distributed with the iPhone/Cocoa Touch SDK. So, for the very quick, but cool observation.

You can easily create a UITextField to handle text input. The interesting part comes into play because there is a keyboard associated with the UITextField, obviously for providing input. That keyboard can be specified what action to do when the return button is pressed, giving a way to process the text. The cool part is, it’s extremely easy for developers to use the many different types of keyboards present on the iPhone. For example, there is a numeric keyboard, the default keyboard, one for entering URLs, one for entering email addresses, and so on. Below is a quick code block, adapted from the “Hello World” example.

aTextField.borderStyle = UITextFieldBorderStyleRounded;
aTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
aTextField.placeholder = @”Your name”;
aTextField.keyboardType = UIKeyboardTypeEmailAddress;

Some other examples of keyboard types:

  • UIKeyboardTypeDefault
  • UIKeyboardTypeNamePhonePad
  • UIKeyboardTypeNumberPad
  • UIKeyboardTypeNumbersAndPunctuation
  • UIKeyboardTypePhonePad
  • UIKeyboardTypeURL
Comments (9) Leave a Comment
  1. Dave March 9th, 2008 at 02:03 | #1

    Does this mean that developers can create a new keypad layout and cause it to pop up as the default keypad?

  2. Matt March 9th, 2008 at 02:14 | #2

    Nope, this simply means that developers will easily be able to tailor the keyboard to the specialized task at hand. All the native Apple apps already do this, but it is nice that Apple provided the functionality so easily to developers.

  3. Brian March 20th, 2008 at 12:37 | #3

    Yes, that keyboardType property is in the HelloWorldClassic sample, but I can’t find it in the documentation of UITextField. Sweet.

  4. Brian March 20th, 2008 at 12:40 | #4

    Nevermind. I see now that the UI reference pages show a “conforms to” section of each class documenting the protocols they conform to.

  5. Rew May 15th, 2008 at 23:12 | #5


    typedef enum {
    UIKeyboardTypeDefault,
    UIKeyboardTypeASCIICapable,
    UIKeyboardTypeNumbersAndPunctuation,
    UIKeyboardTypeURL,
    UIKeyboardTypeNumberPad,
    UIKeyboardTypePhonePad,
    UIKeyboardTypeNamePhonePad,
    UIKeyboardTypeEmailAddress,
    } UIKeyboardType;

    Missing from this list is a keyboard type which is very similar to UIKeyboardTypeNumberPad but includes a period character. I want an input field for a currency value – the best option I have from the above list is UIKeyboardTypeNumbersAndPunctuation but this isn’t as tidy as UIKeyboardTypeNumberPad, the latter only has numerals.

    I’m hoping a new Keyboard Type is added within a future version of the SDK.

  6. Matt May 16th, 2008 at 11:46 | #6

    You could always file a bug report as a feature request.

  7. David December 21st, 2008 at 01:07 | #7

    I’m with Rew, I really need the phone layout with a period. Grr…

  8. tommy January 19th, 2009 at 18:17 | #8

    There’s a typo in the original post: it’s 'UIKeyboardTypeEmailAddress' not 'UIKeyboardTypeSingleEmailAddressing'

  9. Matt January 20th, 2009 at 16:05 | #9

    Thanks!

    I wonder if I made that typo, or if the constant itself has changed since I wrote this post. Either way, the correction is noted and updated in the post :)

Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">
Trackbacks are closed.