F L
F L

Reputation: 498

Custom numbers and characters keyboard for iPhone in Objective C

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

Upvotes: 5

Views: 7231

Answers (3)

rob mayoff
rob mayoff

Reputation: 385500

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.

Upvotes: 2

mergesort
mergesort

Reputation: 672

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;
}

Upvotes: 5

Quentamia
Quentamia

Reputation: 3274

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

Upvotes: 1

Related Questions