Instruction

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

CoreText & TextKit

CoreText is a low-level text engine that, when used alongside the Core Graphics/Quartz framework, gives you fine-grained control over layout and formatting.

CoreText

Here’s a diagram of the CoreText object model:

TextKit

iOS 7 introduced a new framework for working with text and text attributes. All text-based UIKit controls (apart from UIWebView) use TextKit. TextKit provides several classes to control the layout of text, such as NSTextContentStorage, NSTextLayoutManager, and NSTextContainer.

Using Image Glyphs in Custom Text Engines

TextKit and CoreText can take advantage of updated text rendering APIs to provide custom solutions for Genmoji and other image glyphs.

CoreText

For custom typesetting solutions, CoreText provides methods to use an NSAdaptiveImageGlyph as the adaptive image provider that can be queried for appropriate typographic bounds based on the metrics of the current font. It also offers a way to render the image at a given point in the current context:

// Find typographic bounds for image in NSAdaptiveImageGlyph
let provider = adaptiveImageGlyph
let bounds = CTFontGetTypographicBoundsForAdaptiveImageProvider(font, provider)

// Draw it at the typographic origin point on the baseline
CTFontDrawImageFromAdaptiveImageProviderAtPoint(font, provider, point, context)

TextKit

TextKit has a new property and method:

See forum comments
Download course materials from Github
Previous: Introduction