Automatically set keyboard focus to UITextView

Asked on 06/12/2025

1 search

To automatically set keyboard focus to a UITextView, you can use the becomeFirstResponder method on the UITextView instance. This method is part of the UIResponder class, which UITextView inherits from. When you call becomeFirstResponder, it makes the UITextView the first responder, which in turn brings up the keyboard and sets the focus to the text view.

Here's a simple example:

myTextView.becomeFirstResponder()

This line of code should be placed in a context where it makes sense to set the focus, such as after the view has loaded or when a specific user action occurs.

For more detailed information on text improvements and related APIs, you might want to check out the session titled "What’s new in UIKit" from WWDC 2024, specifically the section on text improvements. You can find it at the following timestamp: What’s new in UIKit (16:14).