⬆️ ⬇️

Add a button for UIKeyboardTypeNumberPad

Many developers have come up against the fact that if you select UIKeyboardTypeNumberPad type in UITextField in iOS for iPhone, then there will be an empty space instead of a button at the bottom left.



This type of keyboard does not work the property returnKeyType and it can be removed from the screen only by hanging the handler to touch in an empty place (for example, UIView)



Traffic caution



You can find a lot of examples on the Internet how to add your button to such a keyboard, but I had the task to add a hide button to a translucent keyboard (UIKeyboardAppearanceAlert) to make it look like this:

')





At first, I planned to describe how I solved this problem, but when I finished it to a universal state, I understood that it would be a long and confusing description. In the end, having done everything as a separate class, I will describe how to run.



First of all we download the class itself.



The archive will be three files and a folder with a demo project. We need only these three files:

AMTextFieldNumberPad.h

AMTextFieldNumberPad.m

AMTextFieldNumberPad.bundle (the necessary images are stored in it)



We connect them to the project.



Then in the necessary controller in the header we connect the class:





In the Interface Builder we add a UITextField and assign a class to it.





And make the connection between objects





That's all.



You can also call it programmatically.





Now I will tell about the possibilities of the class.

The class supports a plain and transparent keyboard.



You can add your text to the button:





If the text is not specified, then it will be automatically substituted from returnKeyType:





You can make a button with a keyboard icon (like in iPad):





Or specify any of your own:





Well, support horizontal orientation:





Naturally, I do not pretend to the ideal solution, if anyone knows the best ways - I will be very grateful.



I also attach a link to the repository.

Source: https://habr.com/ru/post/121905/



All Articles