5
votes

In Swift when we choose keyboard style as Decimal Pad, it appears with 10 numbers and separator depending on in what country you are. For example, in Russia, the default decimal separator is ',' while in USA it is '.'.

In my app, I want to show only Decimal Pads with dot '.' and doesn't matter where you are.

I dont want this happen
I want this happen in every device!

It is not about showing right keyboard language.
It is about forcing decimal separator symbol to be '.'(dot) whatever location app user has.
For example, we can force localizaton from Product>Scheme>Edit Scheme>Options>Application Region -> set to US. But I just need to change Decimal symbol, not whole localization.

2
@TamásSengel The edit made to the question makes it clear that it's no longer a possible duplicate. - Ash

2 Answers

0
votes

Subclass your textField and override UIResponder.textInputMode and return Russian for UITextInputMode.primaryLanguage

0
votes

I know this is no longer 2017 but... Overriding the UITextField is pretty easy.

class EnglishTextField: UITextField {
    override var textInputMode: UITextInputMode? { return EnglishInputMode() }
}
class EnglishInputMode : UITextInputMode {
    override var primaryLanguage: String? { "en-US" }
}

Then in the Identity Inspector for that UITextField in your Storyboard, set the Class (at the top) to EnglishTextField.

This works great except for one problem: In 2019, the "primaryLanguage" is never queried before the keyboard is displayed, so it doesn't help at all.

I'm still hoping to find an answer to this myself. In my case, I'm using the "decimal pad" to allow entry of IP Addresses, and those are dotted-decimal in all countries.