iosuser-interfacekeyboardswift3numpad

In iOS how to add a line above the Number Pad, in Swift?


By default if you set a UITextField keyboard type to Number Pad when it is displayed, it appears without a keyline above the top keys (iOS10). Is there an easy way to resolve this?

enter image description here


Solution

  • There are a few options, including adding a 1px UIView to the bottom of your layout (perhaps showing/hiding it based on the keyboard notifications), but by far the simplest solution is to add an empty toolbar as the UITextField's accessory view:

    myTextField.inputAccessoryView = UIToolbar()
    

    Which resolves the issue:

    enter image description here