4. Common Problems with UIKit
Y can apply a font to the text, but the same font is used for the entire view.
ou
UITextView cannot display rich text from an NSAttributedString. There is no Apple-
provided view that can do that.
➢
UIWebView
•
Not ideal for displaying rich text.
•
Requires HTML.
•
The native rich-text data structure -> NSAttributedString
•
Slow, and it provides no easy access to its current contents.
5. Characters and Glyphs
Characters are essentially numbers representing code points in a character set
or encoding scheme.
OSX
✔
Unicode
✔
Provide unique number for every character
✔
Independent of programming language, platform.
6. Glyphs continued..
A glyph is a graphic shape used to depict a character.
numeric codes
✔
glyph codes
✔
Glyphs are selected during composition and layout processing by the character-to-glyph
conversion process.
There are any number of glyphs that correspond to a particular character.
✔
7. Understanding bold, Italics and Underline
✔
Three most common rich-text attributes.
✔
Presented to the user as simple attributes,
✔
But they are quite different from each other.
✔
In typography, you do not “bold” a font by drawing it with thicker lines.
✔
Font designer -> variation.
✔
In iOS the Helvetica font has a variation called Helvetica-Bold.
✔
While these fonts are related, they are completely different.
✔
To find font variations, you use CTFontCreateCopyWithSymbolicTraits.
8. Italic
✔
True italic type is based on calligraphy and uses different shapes (glyphs) than the regular (or
roman) font.
✔
Some fonts do not have a true italic variation -> roman type -> oblique.
✔
When users request italic,
Either italic or oblique.
✔
✔
kCTFontItalicTrait to CTFontCreateCopyWithSymbolicTraits
✔
It returns the best font that matches this looser definition.
✔
Text with both bold and italic requires yet another font variation such as Georgia-BoldItalic.
✔
Underline is a decoration like color or shadow.
✔
You do not change font when you add decorations.
9. Core Text
Core Text is a C-based API that uses Core Foundation naming and memory
management.
Low-level text layout and font-handling engine.
➢
Extremely fast and powerful.
➢
Can handle complex layouts
➢
Multicolumn text
➢
Curved text.
➢
10. Attributed Strings
The fundamental data type in Core Text is CFAttributedString. An attributed string is a
string that applies attributes to ranges of characters.
The attributes can be any key-value pair, but for the purposes of Core Text, they
usually contain style information such as font, color, and indentation.
It is usually best to use CFMutableAttributedString so you can modify the attributes
of various parts of the string. CFAttributedString requires that all of the string have the
same attributes.
Toll free bridge to Cocoa Attributed String (NSAttributed String)
12. CTFrameSetter
●
Highest level object in core text layout engine
●
Generates text frame by filling path with text
●
Applies paragraph styles to the frame text
13. Typesetters
➢ Performs the fundamental text layout operations of character-to-
glyph conversion
➢ Positioning of glyphs into lines.
➢ Suggests line breaks.
➢ CTFramesetter instantiates a typesetter and uses it to create the
line objects used to fill a frame
14. Lines and Glyph Runs
➢CTLine : CoreText Object that represents a line
➢Contains an array of glyph runs
➢Glyph run is a set of consecutive glyphs sharing the same attributes
and direction
➢Created by typesetter during framesetting operations
15. CoreText: Things NOT Covered
➢
CTFont
➢
Run Delegate
- to attach pic, movie in the middle of document
➢
➢
Presenting Big Document
➢
Writing CT to pdf
➢
NSAttributed String and Core Text - ios6
➢
Mixing Different Languages.
➢
CT Editor ?
16. Conclusion
•In the vast majority of cases, UIKit views like UILabel, UITextView, UITextFields are perfectly
adequate.
• If you need a just few stylized words, you can break the sentence into multiple UILabel views.
• For complex styles, UIKit views are insufficient.
•The next tool you should consider is custom view drawing with NSString methods such as
drawInRect:withFont:. This approach is very good for static text.
•If you need to draw highly stylized, dynamic text, then you basically have two options: web views
and Core Text.
• For selectable and editable text, the best option is typically a web view.
• Javascript knowledge is required.
•
17. Conclusion continued..
●
If you don’t need to edit your rich text, then Core Text is a good choice.
●
If you need to perform very complex layout, such as drawing along curves, Core Text may be your only
option.
●
Core Text does not include any capability for text selection, or copy and paste.
●
If you use Core Text, to get good performance use as much as foundation classes.
●
If the user needs to select text, you need to implement that by hand.
●
Whichever option you choose, try to keep your text rendering isolated to a small number of classes so
that you can swap out the engine later.
●
Apple often tries out complicated APIs in its own code before making them public.
●
Eg : UIPageViewController, UICollectionView
18. References
●Core Text Programming Guide
●Quartz 2D Programming Guide. "Text"
●String Programming Guide. “Drawing Strings”
●Text, Web, and Editing Programming Guide
●WWDC 2011 videos.
"Session 511 – Rich Text Editing in Safari on iOS"
●WWDC 2010 videos.
"Session 110 - Advanced Text Handling for iPhone OS"
●http://www.planetclegg.com/projects/WarpingTextToSplines.html