Use custom numeric keyboard on iPad only

1.1k Views Asked by At

New to iPad development. I would like to use a custom numeric keyboard (using a pod) on iPad, but the native one on iPhones. Is it possible to make an extension on UITextField, UITextView to set/get inputView/keyboardType? Or is there an other solution?

myTextField.keyboardType = .decimalPad

extension UITextField {
    ....

    case .decimalPad:
       if UIDevice.current.userInterfaceIdiom == .pad {
    ...
}
1

There are 1 best solutions below

4
dr_barto On

You can set a custom input view using the inputView property of UITextField. If it is not set, the default keyboard (as configured on the text field) will appear when the text field becomes first responder. So only set if to your custom numeric keyboard view when running on iPad and leave it as-is on iPhone.

EDIT

Initially I pointed out inputAccessoryView instead of inputView, hence the confusion in the comments.