Recipe: Making Text-Input-Aware Views

While only a few views support text input by default, with a bit of effort, you can add keyboard support to almost any view. The key is the simple UIKeyInput protocol. By combining it with a little first responder manipulation, you can update any view to offer text input.

Recipe 6-5 illustrates how to transform a standard UIToolbar into a view that accepts keyboard entry, letting users type text directly into the toolbar, as shown in Figure 6-7. As the user types, the toolbar text updates, even properly handling the Delete key.

Image

Figure 6-7 Adding the UIKeyInput protocol to a toolbar transforms the view into ...

Get The Core iOS Developer’s Cookbook, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.