Search code examples
uitextfieldtvos

I want to use it as a UIButton when I tap UITextField


I created a custom keyboard screen on tvOS. If possible, tap on UITextField as it is, I want to transition to the custom keyboard view. But tapping the UITextField always displays the system keyboard. What should I do now?

enter image description here


Solution

  • 1) Make the view controller implement this delegate: UITextFieldDelegate

    class YourViewController: UIViewController, UITextFieldDelegate {
        // ...
        yourTextField.delegate = self
        // ...
    }
    

    2) Return false in textFieldShouldBeginEditing, so the text field doesn't respond and the keyboard doesn't open. Instead, open yours or do whatever you want.

    func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
        // HERE, open your keyboard or do whatever you want
        return false
    }