Controlling Attributes

In iOS 6, NSObject offers methods to control several text attributes. These methods are intended for use by UIResponder subclasses and are part of the UIResponderStandardEditActions informal protocol. This protocol declares common editing commands for the iOS user interface.

The methods of interest include toggleBoldFace:, toggleItalics:, and toggleUnderline:. These three methods apply styles to the current text selection or, if the styles have already been applied, remove them.

To allow these updates, you just tell the responder (in this case, a text view) to enable text attribute editing. The text view or text field in question does all the heavy lifting. You can implement these calls with nothing more than bar button ...

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.