This project consists of a few examples demonstrating how to draw selectable multicolored text in iOS.
ActiveTextView was developed because drawing multi-colored selectable text on iOS is a pain. The sources offered here won't likely be a perfect drop in solution for developers requiring this functionality, but we feel it demonstrates how to accomplish much of the most desired functionality with respect to multi colored text rendering. ActiveTextView works both ARC and non-ARC build enviroments.
The following image is a simple example of what ActiveTextView can do:
You can specify a string to draw, as well as substrings containing different formatting and color.
In addition to specifying custom formatting so specific regions of your text, you can also specify handlers that will get invoked when the user taps on text within a specific region:
ActiveTextView also demonstrates three different techniques for having the text visually respond to user taps:
- The color of the string can be adjusted to indicate that something has been tapped. (Useful for selecting URLs, for example).
- The bounding region of the text can be used to draw a rectangle (or any other shape) behind the text statically.
- The bounding region of the text can be used to draw a rectangle behind the text, but this rectangle can animate between successive positions through the use of the SlidingTextSelectorView class:
Currently, when highlighting selected regions (either with the SlidingTextSelector, or the static background) ActiveTextView doesn't handle regions that span multiple lines.