3

I have a UITextField which shows UIPickerView. To disable the edit menu, I subclassed UITextField and assigned it in the storyboard. But now the textfield is not changing the value according to change in locale. It always shows the value in English even if I switch to Arabic.

class PickerTextField: UITextField {

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }

    override func caretRect(for position: UITextPosition) -> CGRect {
        return CGRect.zero
    }

    func selectionRects(for range: UITextRange) -> [Any] {
        return []
    }

    override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
        UIMenuController.shared.isMenuVisible = false
        self.resignFirstResponder()
        return false
    }
}
Dhruv
  • 2,153
  • 3
  • 21
  • 45
John Doe
  • 2,225
  • 6
  • 16
  • 44

1 Answers1

1

This is a known issue: iOS Storyboard localizable strings do not work on UILabel subclasses. The bug affects both UILabel and UITextField.

Simplest solution would be to localize the text field in code.

pckill
  • 3,709
  • 36
  • 48