Search code examples
iosswiftuikit

how do I change textField keyboard to be Arabic numbers only? Swift / UIKit


I'm trying to make my text field show only Arabic numbers keyboard, no matter what language the device have. I changed the app base language to Arabic and it is still showing me English numbers.

keyboardImage


Solution

  • You can create a subclass like ArabicTextField of UITextField and use textInputMode property to change your keyboard as below

    class ArabicTextField: UITextField {
        override var textInputMode: UITextInputMode? {
            UITextInputMode.activeInputModes.filter
            { $0.primaryLanguage == "ar" }.first ?? super.textInputMode } 
    }