I recently decided that the best solution to the problem was to use instances of NSAttributedString. The documentation seems inadequate, at least for beginners. The answers to stackoverflow were mainly of two types:
I really like the second answer. But I wanted to better understand NSAttributedString, so I provide here the smallest (?) Example of assembling and displaying an attribute string in case it helps others.
I created a new single-window project in Xcode (4.5.2) for iPad using Storiesboards and ARC.
There are no changes to AppDelegate.
I created a new class based on UIView, calling it AttributedStringView. For this simple example, the easiest way is to bind the attribute string on the screen using the drawAtPoint: method, which requires a valid graphics context and which is most easily accessible in the drawRect: method of the UIView subclass.
Here the ViewController.m is completely (no changes to the header file have been made):
And here AttributedStringView.m is completely (no changes have been made to the header file):
tobinjim
source share