iOS Developer Library

Developer

UIKit Framework Reference NSTextAttachment Class Reference for iOS

Options
Deployment Target:

On This Page
Language:

NSTextAttachment

Inheritance


Conforms To


Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 7.0 and later.

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.

  • Initializes a new NSTextAttachment object with the given data.

    Declaration

    Swift

    init(data contentData: NSData?, ofType uti: String?)

    Objective-C

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

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • bounds bounds Property

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

    Declaration

    Swift

    var bounds: CGRect

    Objective-C

    @property(nonatomic) CGRect bounds

    Discussion

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

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • contents contents Property

    Defines the contents for the text attachment.

    Declaration

    Swift

    var contents: NSData?

    Objective-C

    @property(retain, nonatomic) NSData *contents

    Discussion

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

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • fileType fileType Property

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

    Declaration

    Swift

    var fileType: String?

    Objective-C

    @property(retain, nonatomic) NSString *fileType

    Discussion

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

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • image image Property

    Image representing the text attachment contents.

    Declaration

    Swift

    var image: UIImage?

    Objective-C

    @property(retain, nonatomic) UIImage *image

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • File wrapper associated with the text attachment.

    Declaration

    Swift

    var fileWrapper: NSFileWrapper?

    Objective-C

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

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • This character is used to denote an attachment.

    Declaration

    Swift

    var NSAttachmentCharacter: Int { get }

    Objective-C

    enum { NSAttachmentCharacter = 0xFFFC };

    Constants

    • NSAttachmentCharacter

      NSAttachmentCharacter

      Specifies a character that denotes an attachment.

      Available in iOS 7.0 and later.