---
title: "#174: Better Numeric Input with MMNumberKeyboard ⌨️"
url: https://littlebitesofcocoa.com/174-better-numeric-input-with-mmnumberkeyboard
author: Jake Marsh
date: 2016-01-21
published: 2016-01-21
topics: ["Libraries","UIKit"]
description: "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..."
---

# #174: Better Numeric Input with MMNumberKeyboard ⌨️

By Jake Marsh, January 21, 2016. HTML: https://littlebitesofcocoa.com/174-better-numeric-input-with-mmnumberkeyboard

<img src='https://media.littlebitesofcocoa.com/bite-assets/174-better-numeric-keyboards-with-mmnumberkeyboard-example.png' style='max-width: 457px; float: right; margin-left: 20px; margin-bottom: 20px;' />

**iOS** has some great built-in support for different **keyboards** for different types of data, but the built-in <i>numeric-keypad</i> **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](https://github.com/matmartinez/MMNumberKeyboard) by [Matías Martínez](https://github.com/matmartinez) 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**:

``` swift
let numberKeyboard = MMNumberKeyboard(frame: CGRectZero)
numberKeyboard.allowsDecimalPoint = true
numberKeyboard.delegate = self
```

Then we'll set it as the `inputView` of our **text field**:

``` swift
spaceshipPriceTextField = UITextField(frame: CGRectZero)
spaceshipPriceTextField.inputView = numberKeyboard
```

Now, when our **text field** becomes the **first responder**, the **keyboard** will be <i>much</i> more useful. Lastly, we can (optionally) add some **delegate functions**:

``` swift
func numberKeyboard(numberKeyboard: MMNumberKeyboard!, shouldInsertText text: String!) -> Bool
func numberKeyboardShouldReturn(numberKeyboard: MMNumberKeyboard!) -> Bool
```

More info about _MMNumberKeyboard_ can be found at [git.io/numberkeyboard](http://git.io/numberkeyboard)
