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).

What’s new in UIKit
Explore everything new in UIKit, including tab and document launch experiences, transitions, and text and input changes. We’ll also discuss better-than-ever interoperability between UIKit and SwiftUI animations and gestures, as well as general improvements throughout UIKit.

Dive deeper into Writing Tools
With Writing Tools, people can proofread, rewrite, and transform text directly within your app. Learn advanced techniques to customize Writing Tools for your app. Explore formatting options and how they work with rich text editing. If you have a custom text engine, learn how to seamlessly integrate the complete Writing Tools experience, allowing edits directly within the text view.

Get started with Writing Tools
Learn how Writing Tools help users proofread, rewrite, and transform text in your app. Get the details on how Writing Tools interact with your app so users can refine what they have written in any text view. Understand how text is retrieved and processed, and how to support Writing Tools in custom text views.