How do I show the keyboard by default in UITextView?

后端 未结 3 1054
遇见更好的自我
遇见更好的自我 2020-12-23 20:20

I want to create a view that consists solely of a UITextView. When the view is first shown, by default, I\'d like the keyboard to be visible and ready for text

3条回答
  •  孤独总比滥情好
    2020-12-23 20:58

    In Swift

    To automatically show the keyboard, to the following:

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // show keyboard
        textView.becomeFirstResponder()
    }
    

    Notes

    • This assumes that the text view is editable.
    • Works for both UITextView and UITextField
    • To hide the keyboard use textView.resignFirstResponder()

提交回复
热议问题