Buddybuild is a CI, CD and user feedback platform built for mobile development teams - sign up for free and start building better apps!

iOS has some great built-in support for different keyboards for different types of data, but the built-in numeric-keypad keyboard style does leave a few things to be desired (a "done" button, decimal point, a "hide" button, etc).

Today we'll look at a library called MMNumberKeyboard by Matías Martínez that does a great job of filling in these gaps. Let's try it out.

Setting up a text field to use the library's keyboard is extremely straightforward. First we'll create and configure the keyboard:

let numberKeyboard = MMNumberKeyboard(frame: CGRectZero)
numberKeyboard.allowsDecimalPoint = true
numberKeyboard.delegate = self

Then we'll set it as the inputView of our text field:

spaceshipPriceTextField = UITextField(frame: CGRectZero)
spaceshipPriceTextField.inputView = numberKeyboard

Now, when our text field becomes the first responder, the keyboard will be much more useful. Lastly, we can (optionally) add some delegate functions:

func numberKeyboard(numberKeyboard: MMNumberKeyboard!, shouldInsertText text: String!) -> Bool
func numberKeyboardShouldReturn(numberKeyboard: MMNumberKeyboard!) -> Bool

More info about MMNumberKeyboard can be found at git.io/numberkeyboard