NSTextAttachment Class Reference for iOS

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

Overview

NSTextAttachment objects are used by the NSAttributedString class cluster as the values for attachment attributes (stored in the attributed string under the key named NSAttachmentAttributeName). The objects you create with this class are referred to as text attachment objects, or when no confusion will result, as text attachments or merely attachments.

Tasks

Creating Text Attachments

Defining the Contents

Properties

bounds

Defines the layout bounds of the receiver's graphical representation in the text coordinate system.

@property(nonatomic) CGRect bounds
Discussion

The bounds rectangle origin is at the current glyph location on the text baseline. The default value is CGRectZero.

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

contents

Defines the contents for the text attachment.

@property(retain, nonatomic) NSData *contents
Discussion

Modifying this property has the side effect of invalidating the image property.

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

fileType

Defines the file type of the contents for the text attachment.

@property(retain, nonatomic) NSString *fileType
Discussion

Modifying this property has the side effect of invalidating the image property.

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

fileWrapper

File wrapper associated with the text attachment.

@property(retain, nonatomic) NSFileWrapper *fileWrapper
Discussion

Optionally, NSTextAttachment can be associated with a file wrapper. Modifying this property has a side effect of invalidating image, contents, and fileType properties.

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

image

Image representing the text attachment contents.

@property(retain, nonatomic) UIImage *image
Availability
  • Available in iOS 7.0 and later.
Declared In
NSTextAttachment.h

Instance Methods

initWithData:ofType:

Initializes a new NSTextAttachment object with the given data.

- (id)initWithData:(NSData *)contentData ofType:(NSString *)uti
Parameters
contentData

Data to use for the text attachment contents. Can be nil.

uti

A uniform type identifier specifying the data type of the attachment contents. Can be nil.

Return Value

A new NSTextAttachment object.

Discussion

This is the designated initializer.

When either contentData or uti is nil, the receiver is consider to be an attachment without document contents. In this case, the NSAttributedString external file writing methods try to save the value of the image property instead.

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

Constants

Attachment Character

This character is used to denote an attachment.

enum {
   NSAttachmentCharacter = 0xFFFC
};
Constants
NSAttachmentCharacter

Specifies a character that denotes an attachment.

Available in iOS 7.0 and later.

Declared in NSTextAttachment.h.

Declared In
NSTextAttachment.h