Core Text
- It is a Low Level framework used for laying out text and handling fonts.
- Introduced in OSX 10.5 and iOS 3.2.
- It is designed to handle Unicode fonts(computer fonts) natively.
- Tight integration with Core Graphics and Cocoa.
- Use Core Text if we want to render text directly into a Core Graphics context(used for path based drawing).
DRAWING TEXT IN CORE TEXT
- Create a path where the text needs to be drawn.
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddRect(path,NULL,self.bounds);
- Create a text string which is to be drawn.
NSAttributedString *string = [NSAttributedString alloc]initWithString:@"Hello Core Text"];
- Set a text drawing frame.
CTFrameSetterRef frameSetter = CTFramesetterCreateWithAttributesString((CFAttributedStringRef)string);
CTFrameRef frame = CTFramesetterCreateFrame(framesetter,CFRangeMake(0,[string length]),path,NULL);
- Draw the frame in the given context.
CTFrameDraw()
- Create a path where the text needs to be drawn.
CGMutablePathRef path = CGPathCreateMutable();CGPathAddRect(path,NULL,self.bounds);
- Create a text string which is to be drawn.
NSAttributedString *string = [NSAttributedString alloc]initWithString:@"Hello Core Text"];
- Set a text drawing frame.
CTFrameSetterRef frameSetter = CTFramesetterCreateWithAttributesString((CFAttributedStringRef)string); CTFrameRef frame = CTFramesetterCreateFrame(framesetter,CFRangeMake(0,[string length]),path,NULL);
- Draw the frame in the given context.
CTFrameDraw()
FONT METRICS
CTFontGetAscent(CTFontRef font);
CTFontGetDescend(CTFontRef font);
CTFontGetLeading(CTFontRef font);
CTFontGetCapHeight(CTFontRef font);
TEXT KIT
- It is a High Level framework that handles all characteristics of fine Typography.
- Built On Core Text.
- Introduced in iOS7.
Features
- Lays out styled text into Paragraphs,columns and Pages.
- Integrated with UIKit text based controls(now with UITextView and UITextField also).
- Enables to create, edit, store and display text with very less code than previously.
- Responsible to manage multiple fonts.
- Flow text around arbitrary regions such as graphics.
- Developers can add different styles and formatting to the text with help of TextKit.
Things Text Kit Can Do
Paginated Text
Text Wrapping around figures and shapes (Exclusion Paths)
Text Folding :
mechanism to a hide and reveal blocks of text
Custom Truncating :
Mary had a little lamb with fleece as white as snow.
Mary had.......with.........as snow.
Rich Text Editing :
Interactive Text Colouring - changes the attributes of the text when the user types the text.
Enhanced in iOS7 :
All techniques work in standard components.
UITextView and UITextField supports all text attributes. Kerning and Ligatures everywhere by default. Letterpress text effect.
Hit Testing :
Resolving tap to a character index.
Interaction with Links :
new in iOS7,we can turn any arbitrary text range into Links using NSLinkAttributeName. Long Press on it opens the action sheet (default behaviour of iOS7)
Data Detectors :
detects a particular data and performs action.
Text Attachments :
used for inline images
Affects and affected by text layouts.
contains geometry for contained data.
are interactable.
Text Kit new Classes
NSTextStorage : defines the fundamental storage mechanism for text. implements change management, verification of attributes, delegate handling and layout management.
NSTextContainer : defines the region where text is to be laid out.
NSLayoutManager : coordinates the layout and display of characters.Maps Unicode characters to glyphs and sets them in NSTextContainer objects and display them in the series of textview objects.
DRAWING TEXT IN TEXT KIT
- Create a text storage which stores the text to be drawn.
NSTextStorage *textStorage = [NSTextStorage alloc]initWithString:@"Hello Core Text"];
- Add textstorage to textlayout which will handle the text layout.
NSTextLayoutManager *layoutManager = [NSTextLayoutManager alloc]init];
[textStorage addLayoutManager: layoutManager];
- Create a textContainer which defines the region where the text is to be laid.
NSTextContainer = [[NSTextContainer alloc]initWithSize:CGSizeMake(width,height)];
- Add Textcontainer to LayoutManager and add UITextView to the view.
[layoutManager addTextContainer:textContainer];[self.view addsubView:textView];
- Create a UITextView to layout the text with the textContainer and add it to the view.
UITextView *textView = [UITextView alloc]initWithFrame:CGRectMake() textContainer:textContainer];
[self.view addSubView:textView];
- Create a text storage which stores the text to be drawn.
NSTextStorage *textStorage = [NSTextStorage alloc]initWithString:@"Hello Core Text"];
- Add textstorage to textlayout which will handle the text layout.
- Create a textContainer which defines the region where the text is to be laid.
NSTextLayoutManager *layoutManager = [NSTextLayoutManager alloc]init];
[textStorage addLayoutManager: layoutManager];
NSTextContainer = [[NSTextContainer alloc]initWithSize:CGSizeMake(width,height)];
- Add Textcontainer to LayoutManager and add UITextView to the view.
[layoutManager addTextContainer:textContainer];[self.view addsubView:textView];
- Create a UITextView to layout the text with the textContainer and add it to the view.
UITextView *textView = [UITextView alloc]initWithFrame:CGRectMake() textContainer:textContainer]; [self.view addSubView:textView];
Text Kit design
Font Metrics
Line Height Cap Height Leading Ascent Descent
Baseline
Thank you
deck
By Torry Harris Business Solutions
deck
- 1,898