iOS Developer Library

Developer

UIKit Framework Reference NSTextAttachmentContainer Protocol Reference

Options
Deployment Target:

On This Page
Language:

NSTextAttachmentContainer

Inheritance


Not Applicable

Conforms To


Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 7.0 and later.

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

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

    Declaration

    Swift

    func attachmentBoundsForTextContainer(_ textContainer: NSTextContainer, proposedLineFragment lineFrag: CGRect, glyphPosition position: CGPoint, characterIndex charIndex: Int) -> CGRect

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    func imageForBounds(_ imageBounds: CGRect, textContainer textContainer: NSTextContainer, characterIndex charIndex: Int) -> UIImage!

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.