5

The keyboard shown below is not part of the defaults supplied by Cocoa, so it has to be custom built. I need to create a keyboard that looks just like the one below.

I've seen a few apps out there that use it, I saw some tutorials that add a custom bar on top with some buttons, but I need it to look and function just like a normal keyboard but with an extra row of numbers.

How can this be done programmatically in Objective C? Can someone please point me in the right direction?

enter image description here

Community
  • 1
  • 1
F L
  • 478
  • 1
  • 7
  • 18
  • 1
    possible duplicate of [iPad custom Keyboard GUI](http://stackoverflow.com/q/2558806/), http://stackoverflow.com/q/4459375/, http://stackoverflow.com/q/8322989/, http://stackoverflow.com/q/1610542/, http://stackoverflow.com/q/5603103/, http://stackoverflow.com/q/789682/, http://stackoverflow.com/q/9451912, http://stackoverflow.com/q/1332974/ – jscs May 31 '12 at 18:20
  • 2
    Basically the entire first page of a [search for "custom iphone keyboard"](http://stackoverflow.com/search?q=custom+iphone+keyboard). – jscs May 31 '12 at 18:23

3 Answers3

5

You could use a UIToolbar and add the 0-9 buttons on there. You can even color, or tint it to be grey like the iPhone keyboard, but there is no way that I know of to add onto the actual keyboard view.

//Feel free to change the formatting to suit your needs more
//And of course, properly memory manage this (or use ARC)

UIBarButtonItem *my0Button = [[UIBarButtonItem alloc] initWithTitle:@"0" style:UIBarButtonItemStyleBordered target:self action:@selector(addNumberToString:)];
UIBarButtonItem *my1Button = [[UIBarButtonItem alloc] initWithTitle:@"1" style:UIBarButtonItemStyleBordered target:self action:@selector(addNumberToString:)];

UIToolbar *extraRow = [[UIToolbar alloc] init];
extraRow.barStyle = UIBarStyleBlack;
extraRow.translucent = YES;
extraRow.tintColor = [UIColor grayColor];
[extraRow sizeToFit];
NSArray *buttons = [NSArray arrayWithObjects: my0Button, my1Button, etc, nil];
[extraRow setItems:buttons animated:YES];
textView.inputAccessoryView = extraRow;



-(void) addNumberToString: (id) sender
{
    //Where current string is the string that you're appending to in whatever place you need to be keeping track of the current view's string.
    currentString = [currentString stringByAppendingString: ((UIBarButtonItem *) sender).title;
}
mergesort
  • 672
  • 4
  • 10
2

The image in your question is from the 5RowQWERTY project: http://code.google.com/p/networkpx/wiki/Using_5RowQWERTY

This project only works on a jailbroken device (as far as I can tell) and certainly uses private APIs, making it unacceptable for the app store. If those restrictions are ok with you, then just use that project. It installs a new keyboard layout file (layout.plist).

If you want to run on non-jailbroken devices, or put your app in the app store, you won't be able to use that method. I see three options:

  1. Dig around in the keyboard's view hierarchy after it appears (it has its own UIWindow so start with the [[UIApplication sharedApplication] windows] array) and add your own number buttons. This is a lot of work, very tricky to do well, and quite likely to be rejected by Apple anyway.

  2. Reimplement the keyboard from scratch. This is a huge amount of work if you want to support multiple keyboard layouts and truly match the feel and behavior of the system keyboard.

  3. Give up and just set inputAccessoryView to a row of number buttons. This is easy.

My advice is that anything but option 3 is a waste of time. Just use an inputAccessoryView to display a number bar and move on to the parts of your app that add real value for your users.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • Yes, that is correct, that is where I got an image. My question how that can be done. Definitely cannot have jailbroken or rejected app. Sounds like painful option 2 maybe the one I'll have to follow because the client definitely wants that keyboard. Thanks! – F L May 31 '12 at 19:06
1

That's an extremely open ended question. You're basically asking "How do I create a custom view in iOS?"

Here are a few points to start:

  1. You're creating a new view that has the appearance of the system's default keyboard. You'll need to gather resources (either create them or get free ones) for each of the keyboard's buttons.

  2. You can put all of this together in IB. Your view in nothing more than a collection of UIButtons.

  3. To use the keyboard, you'll assign your view as the inputView.

Here's a tutorial that builds a custom inputView: http://www.raywenderlich.com/1063/ipad-for-iphone-developers-101-custom-input-view-tutorial

Quentamia
  • 3,244
  • 3
  • 33
  • 42
  • The question is not on how to build a custom view, but how to add a numeric button row to a default keyboard. – F L May 31 '12 at 18:09