5

I am looking to implement a custom toolbar that sits above my keyboard for a text field with some custom values. I've found a ton of tutorials online but this question is for asking what's the best way to do this.

This tutorial here http://blog.carbonfive.com/2012/03/12/customizing-the-ios-keyboard/ provides the most common way I can see across many tutorials, with creating a new subclass of UIView and using delegates to get that information across.

That's the commonality. However, I came across this tutorial which in the view controller itself just creates the toolbar, assigns it to the textField inputAccessory and it's good to go. In fact, I tried out the code and without any effort, I have now a custom keyboard.

http://easyplace.wordpress.com/2013/03/29/adding-custom-buttons-to-ios-keyboard/

This just seems a bit too easy to me though and I'd think the proper, Apple recommended way would be to create that UIView subclass and use delegates so that the view controller with the text fields acts as that delegate.

I'm specifically targeting iOS 7 in my app.

What are people's thoughts on this? If the second easier link is supported and is likely to pass Apple's guidelines, it's a good starting point but if delegates are the way to go, I'd rather look into that from the start.

Your thoughts will be appreciated.

amitsbajaj
  • 1,304
  • 1
  • 24
  • 59

2 Answers2

3

There is no 'Apple Approved' way to do this, and its hard to believe anything you do here would get your app rejected. The custom keyboard you reference in your post has the iOS6 look and will appear outdated in an iOS6 app. I'll mention some iOS7 suggestions shortly, but the constant danger of mimicking what the System looks like today is guaranteed to look outdated later. In Mac/Cocoa development, Apple use to say at the WWDC that if you did something custom, make it look custom, don't take a standard Apple widget and try to duplicate it. But that advice is mostly ignored.

For iOS 7, you can create buttons that appear just like the system ones do (not pressed), but of course when someone presses them, they won't act like system buttons (i.e. animate up and "balloon" out.

I'm currently using a fantastic add-on keyboard, my fork of KOKeyboard (which uses the buttons above). This is such a cool addition. While the buttons look like iPad buttons, each one has 5 keys in it. By dragging to a corner you select one of the four, and tapping in the middle gives you that key. This might be overkill for your app, but it really helped me with mine. It looks like this:

enter image description here

(the Key / Value is in the under laying view.) The center control lets you move the cursor - its like a joy stick - and can be used to both move and select text. Amazing class, I wish I'd invented it!

Also, for any solution, you want to use a UIToolbar as the view holding the keys, for the reason that it supports blur of the view it overlays, just like the keyboard does. You can use the UIToolbar with no bar button items in it (if you want), and just add subviews. This is a "trick" I learned here, as there is no other way to get blur!

David H
  • 40,852
  • 12
  • 92
  • 138
  • Thank you David for a response that honestly couldn't be better. That is very informative and wow, that is one hell of a class you have there! I absolutely love the buttons, the concept and the joy-stick like approach. Brilliant. That's super helpful though and with iOS 7 in mind, I will certainly use a UIToolbar for the holding of the values because I do love the blur effect all over iOS 7! Thanks again for a brilliant answer! What's your app by the way? I'm wondering why I haven't already downloaded that masterpiece :) – amitsbajaj Nov 29 '13 at 23:27
  • My "app" is a an internally used app to access our MongoDB database. It just got the light of day. But that's why I used all open source - so others could leverage it. And as I said the KOKeyboard was not mine originally - I wish I could lay claim to it but sadly cannot. That said I'm keeping it current! – David H Nov 30 '13 at 00:43
  • Hi guys, the joystick button that can move the cursor, can it be a reason to reject an app in the AppStore, for custom keyboard? – Solidus Nov 18 '14 at 12:26
  • @Solidus why would it? No private Apis used. It's not a custom keyboard, it's a accessory view. – David H Nov 18 '14 at 12:52
  • Sorry i'm not very good at english and maybe I didn't understand well your answer for Lavanya. Is the accessory view could be used in iOS 8 custom keyboard (in the appstore)? And if I put a button like the joystick in the keyboard, is it a reason to reject app? thanks – Solidus Nov 18 '14 at 13:05
  • 1
    @Solidus, my 2nd lang. is pretty awful too. The joystick is not part of the keyboard, its part of an accessory view. I do not believe you can have a custom keyboard WITH a accessory view as an extension. But if you create your own keyboard with normal keys, and add the KOKeyboard into it, well, I don't believe Apple would reject it. But that is a lot of work for sure. Also, for KOKeyboard, your choice of keys for each of the 4 big buttons is context sensitive - i.e. is person entering JSON, regex, etc. You could just integrate the joystick with a plain kb, that should also be acceptable. – David H Nov 18 '14 at 13:59
  • I was thinking that moving the cursor is not acceptable by Apple, Thanks for your answers – Solidus Nov 18 '14 at 21:13
1

David's KOKeyboard (er…, the one he used - see David's comment below) looks nice. I suspect that he is using the official Apple mechanism:

inputAccessoryView

Typically, you'd set that value on a UITextView, but it can be any class that allows itself to become the first responder.

The provided view will be placed above the default apple keyboard.

It is correct that there is no official mechanism (and it is suggested against) to modify any system provided keyboard. You can add to it, as above. You can also entirely replace it for with your own mechanism. Apply will forgo the keyboard setting on your view and use a custom input mechanism if you set

inputView

set it to any view - Apple will still manage its appearance and dismissal as it does the custom keyboards.

Edit: Of course, iOS 8.x added significant access to keyboards. (not mentioned here)

bshirley
  • 8,217
  • 1
  • 37
  • 43
  • Just saw your post! I wish I'd created it but didn't - I just modernized it a bit. When I demoed it to my coworkers they all ooooed and ahhhhhhed! – David H Nov 18 '14 at 12:54