NSTextAttachmentContainer Protocol Reference

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

Overview

The NSTextAttachmentContainer protocol defines the interface to text attachment objects from NSLayoutManager.

Tasks

New Methods

Instance Methods

attachmentBoundsForTextContainer:proposedLineFragment:glyphPosition:characterIndex:

Returns the layout bounds of the text attachment to the layout manager. (required)

- (CGRect)attachmentBoundsForTextContainer:(NSTextContainer *)textContainer proposedLineFragment:(CGRect)lineFrag glyphPosition:(CGPoint)position characterIndex:(NSUInteger)charIndex
Parameters
textContainer

The text container for the text being laid out.

lineFrag

The line fragment containing the text attachment.

position

The glyph location inside lineFrag which is the origin of the returned bounds rectangle.

charIndex

The character location inside the text storage for the attachment character.

Return Value

The bounds rectangle of the text attachment if not CGRectZero; otherwise, the rectangle of the size property of the attachment’s image property.

Discussion

Conforming objects can implement more sophisticated logic for negotiating the attachment bounds based on the available container space and proposed line fragment rectangle.

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

imageForBounds:textContainer:characterIndex:

Returns the image object rendered by the layout manager in the given image bounds rectangle inside the text container. (required)

- (UIImage *)imageForBounds:(CGRect)imageBounds textContainer:(NSTextContainer *)textContainer characterIndex:(NSUInteger)charIndex
Parameters
imageBounds

The rectangle in which the image is laid out.

textContainer

The text container in which the image is laid out.

charIndex

The character location inside the text storage for the attachment character.

Return Value

The image rendered in the bounds rectangle.

Discussion

The method should return an image appropriate for the target rendering context derived by arguments passed into this method. The NSTextAttachment implementation returns the text attachment’s image when non-nil. If the image is nil, it returns an image based on the text attachment’s contents and fileType properties.

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