Skip to content


Subversion checkout URL

You can clone with
Download ZIP
100644 85 lines (70 sloc) 3.988 kB
798f57f Moved the README to Markdown
Adrian Kosmaczewski authored
1 Core Text Objective-C Wrapper
2 =============================
4 Introduction
5 ------------
7 One of the most promising and mysterious new frameworks introduced in
8 iOS 3.2 is Core Text. Apple defines Core Text as a “text drawing
9 engine”, which allows Mac (and now iPad) apps to render rich text on any
10 graphics context. Strings drawn with Core Text feature lots of custom
11 settings such as detailed font information, columns, variable line and
12 paragraph heights and several different attributes, which designers and
13 font aficionados surely understand much better than I do. Many new apps
14 have been using this framework since the release of the iPad,
15 particularly newspapers and ebook reader applications, rendering
16 gorgeous text in custom fonts, many of them not available natively in
17 iOS. This framework is also used in lifestyle and corporate
18 applications, too, where using a custom font is sometimes required to
19 match the specifications of brands and trademarks.
21 ![image](
23 It is very important to understand that Core Text is really just a text
24 drawing engine to be used on top of Quartz (Core Graphics), to render
25 rich text on any graphics context. Core Text cannot be used to create a
26 rich text editor, for example, so don’t expect to extend UITextView with
27 it. But you can use it to draw any kind of rich text on screen, which
28 can make you avoid using UIWebView instances for that.
30 Features
31 --------
33 One of the most interesting capabilities of Core Text is being able to
34 render text in several columns. However, Core Text is a C-based
35 framework, and I think that understanding and using the concepts and
36 structures required to render text in columns can be particularly
37 tricky. To make the my life and that of my fellow developers easier,
38 this project contains a small set of Objective-C classes that
39 encapsulate the creation of framesetters, attributed strings and other
40 constructions, and takes care of the creation of several columns, as
41 well as the division of the text in several pages if required.
43 The API interface is very simple (on purpose) and I’m pretty sure you’ll
44 be able to integrate it very easily in your own projects, particularly
45 if you look at the sample project where the classes are used. I’ve also
46 added a category for UIFont, that returns the associated CTFontRef
47 pointer, in a similar fashion to UIImage, which is able to return a
48 pointer to the underlying CGImageRef pointer. It also allows to create a
49 CTFontRef from any font embedded in the application bundle. I am puzzled
50 that the framework designers haven’t included this by default in UIKit.
52 What’s next
53 -----------
55 A future extension I’d like to add would be a couple of categories to
56 parse simple RTF or HTML strings (to start with, probably just with bold
57 and italic text) and create the appropriate attributed string from it;
58 there’s a couple of AppKit extensions to NSAttributedString that do
59 exactly that, but for the moment they are only available in the Mac
60 version of Cocoa, and I haven’t found anything similar for iOS yet.
62 Thanks
63 ------
65 The following people have helped this project grow, with pull requests,
66 comments or bug reports:
68 - [Jared Crawford]( contributed
69 support for shadows in AKOCustomFontLabel.
70 - [Christian Menschel]( contributed the
71 AKOMultiColumnTextViewDataSource protocol to add custom views in the
72 text columns.
74 License
75 -------
77 The code, as usual, is available through with BSD license (see the
78 LICENSE file), so feel free to use it and even contribute bug fixes or
79 enhancements if you want. The font embedded in the project is Polsku
80 Regula, [available through the Open Font
81]( The
82 project requires Xcode 3.2.3 and the iOS SDK 4.0, and it creates a
83 simple application that works on the iPad (iOS 3.2). As usual, use it at
84 your own risk. Enjoy!
Something went wrong with that request. Please try again.