Adding Toolbar for Number Pad in iOS

This is pretty old trick but since this question has been asked on StackOverFlow number of times I am going to cover it here. Let's say that you have a UITextField which shows a Number Pad. By default Number Pad does not gets dismissed since there is no "Return" or the "Done" button. We can easily add a UIToolbar as an accessory view of the UITextField which will allow us to add our own custom UIBarButtonItems. 

// create accessory view for the number pad 
let numberPadToolbar = UIToolbar(frame: CGRectMake(0,0,self.view.bounds.size.width,44))
numberPadToolbar.barTintColor = UIColor(fromHexString: "0B97FF")

numberPadToolbar.items = [UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil),UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Done, target: self, action: "done:")]
self.majorIdTextField.inputAccessoryView = numberPadToolbar
self.minorIdTextField.inputAccessoryView = numberPadToolbar

The result is display below: