NSLayoutManagerDelegate Protocol Reference for iOS

Conforms to
Framework
/System/Library/Frameworks/UIKit.framework
Availability
Available in iOS 7.0 and later.
Declared in
NSLayoutManager.h

Overview

The NSLayoutManagerDelegate protocol defines the optional methods implemented by delegates of NSLayoutManager objects.

Tasks

Handling Line Fragments

Interacting with Text Containers

Laying out Glyphs

Instance Methods

layoutManager:boundingBoxForControlGlyphAtIndex:forTextContainer:proposedLineFragment:glyphPosition:characterIndex:

Returns the bounding rectangle for the specified control glyph with the specified parameters.

- (CGRect)layoutManager:(NSLayoutManager *)layoutManager boundingBoxForControlGlyphAtIndex:(NSUInteger)glyphIndex forTextContainer:(NSTextContainer *)textContainer proposedLineFragment:(CGRect)proposedRect glyphPosition:(CGPoint)glyphPosition characterIndex:(NSUInteger)charIndex
Parameters
layoutManager

The layout manager doing the layout.

glyphIndex

The index of the control glyph in question.

textContainer

The text container to use to calculate the position.

proposedRect

The proposed line fragment rectangle.

glyphPosition

The position of the glyph in textContainer.

charIndex

The character index in textContainer.

Return Value

The bounding rectangle for the specified control glyph with the specified parameters.

Discussion

Sent for resolving the glyph metrics for NSControlCharacterWhitespaceAction control character.

Availability
  • Available in iOS 7.0 and later.
Declared In
NSLayoutManager.h

layoutManager:didCompleteLayoutForTextContainer:atEnd:

Informs the delegate that the given layout manager has finished laying out text in the given text container.

- (void)layoutManager:(NSLayoutManager *)layoutManager didCompleteLayoutForTextContainer:(NSTextContainer *)textContainer atEnd:(BOOL)layoutFinishedFlag
Parameters
layoutManager

The layout manager doing the layout.

textContainer

The text container in which layout is complete. If nil, if there aren’t enough containers to hold all the text; the delegate can use this information as a cue to add another text container.

layoutFinishedFlag

If YES, layoutManager is finished laying out its text—this also means that textContainer is the final text container used by the layout manager. Delegates can use this information to show an indicator or background or to enable or disable a button that forces immediate layout of text.

Discussion

This message is sent whenever a text container has been filled. This method can be useful for paginating.

Availability
  • Available in iOS 7.0 and later.
Declared In
NSLayoutManager.h

layoutManager:lineSpacingAfterGlyphAtIndex:withProposedLineFragmentRect:

Returns the spacing after the line ending with the given glyph index.

- (CGFloat)layoutManager:(NSLayoutManager *)layoutManager lineSpacingAfterGlyphAtIndex:(NSUInteger)glyphIndex withProposedLineFragmentRect:(CGRect)rect
Parameters
layoutManager

The layout manager doing the layout.

glyphIndex

The index of the glyph at the end of the line.

rect

The proposed line fragment rectangle for the current line.

Return Value

The line spacing after the current line.

Discussion

This message is sent while each line is laid out to enable the layout manager delegate to customize the shape of line.

Availability
  • Available in iOS 7.0 and later.
Declared In
NSLayoutManager.h

layoutManager:paragraphSpacingAfterGlyphAtIndex:withProposedLineFragmentRect:

Returns the paragraph spacing after the line ending with the given glyph index.

- (CGFloat)layoutManager:(NSLayoutManager *)layoutManager paragraphSpacingAfterGlyphAtIndex:(NSUInteger)glyphIndex withProposedLineFragmentRect:(CGRect)rect
Parameters
layoutManager

The layout manager doing the layout.

glyphIndex

The index of the glyph at the end of the line.

rect

The proposed line fragment rectangle for the current line.

Return Value

The parapgraph spacing after the current line.

Discussion

This message is sent while each line is laid out to enable the layout manager delegate to customize the shape of line.

Availability
  • Available in iOS 7.0 and later.
Declared In
NSLayoutManager.h

layoutManager:paragraphSpacingBeforeGlyphAtIndex:withProposedLineFragmentRect:

Returns the paragraph spacing before the line starting with the given glyph index.

- (CGFloat)layoutManager:(NSLayoutManager *)layoutManager paragraphSpacingBeforeGlyphAtIndex:(NSUInteger)glyphIndex withProposedLineFragmentRect:(CGRect)rect
Parameters
layoutManager

The layout manager doing the layout.

glyphIndex

The index of the glyph at the beginning of the line.

rect

The proposed line fragment rectangle for the current line.

Return Value

The parapgraph spacing before the current line.

Discussion

This message is sent while each line is laid out to enable the layout manager delegate to customize the shape of line.

Availability
  • Available in iOS 7.0 and later.
Declared In
NSLayoutManager.h

layoutManager:shouldBreakLineByHyphenatingBeforeCharacterAtIndex:

Sent while determining the hyphenation point.

- (BOOL)layoutManager:(NSLayoutManager *)layoutManager shouldBreakLineByHyphenatingBeforeCharacterAtIndex:(NSUInteger)charIndex
Parameters
layoutManager

The layout manager doing the layout.

charIndex

Index of the character delimiting the hyphenation point search.

Return Value

YES if the current hyphenation point is acceptable; NO if the layout manager should find the next hyphenation opportunity before charIndex.

Availability
  • Available in iOS 7.0 and later.
Declared In
NSLayoutManager.h

layoutManager:shouldBreakLineByWordBeforeCharacterAtIndex:

Sent while determining the soft line break point.

- (BOOL)layoutManager:(NSLayoutManager *)layoutManager shouldBreakLineByWordBeforeCharacterAtIndex:(NSUInteger)charIndex
Parameters
layoutManager

The layout manager doing the layout.

charIndex

Index of the character delimiting the break point search.

Return Value

YES if the current line break point is acceptable; NO if the layout manager should find the next break point opportunity before charIndex.

Availability
  • Available in iOS 7.0 and later.
Declared In
NSLayoutManager.h

layoutManager:shouldGenerateGlyphs:properties:characterIndexes:font:forGlyphRange:

Enables customizing the initial glyph generation process.

- (NSUInteger)layoutManager:(NSLayoutManager *)layoutManager shouldGenerateGlyphs:(const CGGlyph *)glyphs properties:(const NSGlyphProperty *)props characterIndexes:(const NSUInteger *)charIndexes font:(UIFont *)aFont forGlyphRange:(NSRange)glyphRange
Parameters
layoutManager

The layout manager doing the layout.

glyphs

A pointer to the layout manager's glyph cache.

props

A pointer to a buffer containing glyph properties for the glyphs in the cache.

charIndexes

A pointer to the starting index for the characters in the text storage for which glyphs are generated.

aFont

A font to override the font attributes in the text storage for the specified character range.

glyphRange

The range of glyphs in the glyph cache to set.

Return Value

The actual glyph range stored in this method. By returning 0, it can indicate for the layout manager to do the default processing.

Discussion

This message is sent whenever the layout manager is about to store the initial glyph information via setGlyphs:properties:characterIndexes:font:forGlyphRange:. To customize the initial glyph generation process, this method can invoke setGlyphs:properties:characterIndexes:font:forGlyphRange: with modified glyph information.

Availability
  • Available in iOS 7.0 and later.
Declared In
NSLayoutManager.h

layoutManager:shouldUseAction:forControlCharacterAtIndex:

Returns the control character action for the control character at the given character index.

- (NSControlCharacterAction)layoutManager:(NSLayoutManager *)layoutManager shouldUseAction:(NSControlCharacterAction)action forControlCharacterAtIndex:(NSUInteger)charIndex
Parameters
layoutManager

The layout manager doing the layout.

action

The proposed control character action for the character at the given index. Possible values are enumerated by NSControlCharacterAction.

charIndex

The index of the control character for which the action is proposed.

Return Value

The control character action for the control character at the given index.

Availability
  • Available in iOS 7.0 and later.
Declared In
NSLayoutManager.h

layoutManager:textContainer:didChangeGeometryFromSize:

Sent right before the layout manager invalidates layout due to the text container changing geometry.

- (void)layoutManager:(NSLayoutManager *)layoutManager textContainer:(id)textContainer didChangeGeometryFromSize:(CGSize)oldSize
Parameters
layoutManager

The layout manager invalidating layout.

textContainer

The text container that changed geometry.

oldSize

The size of the text container before it changed geometry.

Discussion

The delegate can react to the geometry change and perform adjustments such as recreate an exclusion path.

Availability
  • Available in iOS 7.0 and later.
Declared In
NSLayoutManager.h

layoutManagerDidInvalidateLayout:

Informs the delegate that the given layout manager has invalidated layout information (not glyph information).

- (void)layoutManagerDidInvalidateLayout:(NSLayoutManager *)sender
Parameters
sender

The layout manager that invalidated layout.

Discussion

This message is sent only when layout was complete and then became invalidated for some reason. Delegates can use this information to show an indicator of background layout or to enable a button that forces immediate layout of text.

Availability
  • Available in iOS 7.0 and later.
Declared In
NSLayoutManager.h