Twitter Specific Keyboard – UIKeyboardTypeTwitter

In a series of previous posts I wrote about the integrated Twitter support that was introduced in iOS 5. If you are creating a custom control such as a UITextField or UITextView, there is a keyboard type specifically designed for writing tweets – the keyboard includes the characters @ and # on the primary view (no tapping necessary for a secondary keyboard view).

The image below shows the new keyboard:


The following code example shows how to set the twitter keyboard in a UITextView:

UITextView	*twitterView;
 
...
 
twitterView = [[UITextView alloc] initWithFrame:CGRectMake(10, 40, 300, 100)];
[twitterView setBackgroundColor:[UIColor whiteColor]];
[twitterView setFont:[UIFont fontWithName:@"Arial" size:18]];
[twitterView setKeyboardType:UIKeyboardTypeTwitter];
 
[[self view] addSubview:twitterView];
  1. Thank you for the tip, John.

    Although I have to admit I came here thinking this post was about a different topic: how to create your own keyboard. You see, I’ve been trying for a long time to create a keyboard specifically for my app (mostly numbers, a return key, the decimal point, and next a previous buttons) because none of Apple’s standard keyboards have what I need (or have too much that I don’t need).

    So, if you ever think of making a tutorial, could you please consider making it about creating your own keyboard that works with an undefined number of UITextFields? Thank you! :)

Comments are closed.