This project consists of a few examples demonstrating how to draw selectable multicolored text in iOS, using CoreText.
Objective-C
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
ActiveTextView.xcodeproj
ActiveTextView
lib
.gitignore
LICENSE
README.md

README.md

ActiveTextView

This project consists of a few examples demonstrating how to draw selectable multicolored text in iOS.

Summary

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:

Image

You can specify a string to draw, as well as substrings containing different formatting and color.

Image

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:

Image

ActiveTextView also demonstrates three different techniques for having the text visually respond to user taps:

  1. The color of the string can be adjusted to indicate that something has been tapped. (Useful for selecting URLs, for example).
  2. The bounding region of the text can be used to draw a rectangle (or any other shape) behind the text statically.
  3. 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:

Image

Known Issues

Currently, when highlighting selected regions (either with the SlidingTextSelector, or the static background) ActiveTextView doesn't handle regions that span multiple lines.