[Text Relatives]
With TextKit the resources at your disposal range from framework objects—such as text views, text fields, and web views—to text layout engines that you can use directly to draw, lay out, and otherwise manage text. Underlying the text views in UIKit is a powerful layout engine called Text Kit.
TextKit 让为我们提供了各种objects以及layout engine(渲染排版用). 下图是常用排版术语:
The UIKit framework provides three primary classes for displaying this text content in an app’s user interface:
-
UILabeldefines a label, which displays a static text string. -
UITextFielddefines a text field, which displays a single line of editable text. -
UITextViewdefines a text view, which displays multiple lines of editable text.
Labels and text fields are intended to be used for relatively small amounts of text, typically a single line. Text views, on the other hand, are meant to display large amounts of text. When working with editable text fields and text views, you should always provide a delegate object to manage the editing session. Text views send several differentnotifications to the delegate to let them know when editing begins, when it ends, and to give them a chance to override some editing actions.
Characters and glyphs do not have a one-to-one correspondence. In some cases a character may be represented by multiple glyphs, such as an “é” which may be an “e” glyph combined with an acute accent glyph “´”. In other cases, a single glyph may represent multiple characters, as in the case of a ligature, or joined letter. Figure 2-2 shows individual characters and the single-glyph ligature often used when they are adjacent.
The glyphs used to depict characters are selected by the layout manager during composition and layout processing. The layout manager determines which glyphs to use and where to place them in the display, or view. The layout manager caches the glyph codes in use and provides methods to convert between characters and glyphs and between characters and view coordinates.
[The Sequence of Messages to the Delegate]
The following code listings use a date-formatter object to illustrate the use of formatters.
1 - (void)viewDidLoad { 2 [super viewDidLoad]; 3 dateFormatter = [[NSDateFormatter alloc] init]; 4 [dateFormatter setGeneratesCalendarDates:YES]; 5 [dateFormatter setLocale:[NSLocale currentLocale]]; 6 [dateFormatter setCalendar:[NSCalendar autoupdatingCurrentCalendar]]; 7 [dateFormatter setTimeZone:[NSTimeZone defaultTimeZone]]; 8 [dateFormatter setDateStyle:NSDateFormatterShortStyle]; // example: 4/13/10 9 DOB.placeholder = [NSString stringWithFormat:@"Example: %@", [dateFormatter stringFromDate:[NSDate date]]]; 10 11 // code continues.... 12 }