Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 752
F L Avatar asked May 31 '12 17:05

F L


People also ask

Can you create a custom keyboard on iPhone?

The xKeyboard is a keyboard extension in which you can add special symbols and words as you needs. There are lots of unicode characters and special symbols you can use. You could use the custom keyboard you build in word, PPT, Excel, notes and other text apps on iPhone or iPad.


2 Answers

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;
}
like image 196
mergesort Avatar answered Sep 29 '22 17:09

mergesort


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.

like image 24
rob mayoff Avatar answered Sep 29 '22 18:09

rob mayoff