Inherits from NSObject
Conforms to NSCoding
Declared in DTTextAttachment.h

Overview

An object to represent an attachment in an HTML/rich text view.

Properties

attributes

The attributes dictionary of the attachment.

@property (nonatomic, strong) NSDictionary *attributes

Discussion

If initialized from HTML, the values of this dictionary are transferred from the give HTML element. If you wish to add custom attribute values to be written to and read from HTML, be aware that the attribute name will be lowercased in compliance with W3C recommendations. Therefore, you may set a camel-case name and persist to HTML, but you will receive a lowercase name when the HTML is transformed into an attributed string.

Declared In

DTTextAttachment.h

contentURL

The URL representing the content

@property (nonatomic, strong) NSURL *contentURL

Declared In

DTTextAttachment.h

displaySize

The size to use for displaying/layouting the receiver

@property (nonatomic, assign) CGSize displaySize

Declared In

DTTextAttachment.h

hyperLinkGUID

The GUID of the hyperlink that this is a part of. All parts of a hyperlink have the same GUID so that they can highlight together.

@property (nonatomic, strong) NSString *hyperLinkGUID

Declared In

DTTextAttachment.h

hyperLinkURL

The hyperlink URL of the receiver.

@property (nonatomic, strong) NSURL *hyperLinkURL

Declared In

DTTextAttachment.h

originalSize

The size of the receiver according to width/height HTML attribute or CSS style attribute

@property (nonatomic, assign) CGSize originalSize

Declared In

DTTextAttachment.h

verticalAlignment

The vertical alignment of the receiver

@property (nonatomic, assign) DTTextAttachmentVerticalAlignment verticalAlignment

Declared In

DTTextAttachment.h

Class Methods

registerClass:forTagName:

Registers your own class for use when encountering a specific tag Name. If you register a class for a previously registered class (or one of the predefined ones (img, iframe, object, video) then this replaces this with the newer registration.

+ (void)registerClass:(Class)theClass forTagName:(NSString *)tagName

Parameters

theClass

The class to instantiate in textAttachmentWithElement:options: when encountering a tag with this name

tagName

The tag name to use this class for

Discussion

These registrations are permanent during the run time of your app. Custom attachment classes must implement the initWithElement:options: initializer and can implement the DTTextAttachmentDrawing and/or DTTextAttachmentHTMLPersistence protocols.

Declared In

DTTextAttachment.h

registeredClassForTagName:

The class to use for a tag name

+ (Class)registeredClassForTagName:(NSString *)tagName

Parameters

tagName

The tag name

Return Value

The class to use for attachments with with tag name, or nil if this should not be an attachment

Declared In

DTTextAttachment.h

textAttachmentWithElement:options:

Initialize and return a DTTextAttachment with the specified DTHTMLElement and options. Convenience initializer. The element must have a valid tagName. The size of the returned text attachment is determined by the element, constrained by the option’s key for DTMaxImageSize. Any valid image resource included in the element (denoted by the method attributeForKey: “src”) is loaded and determines the text attachment size if it was not known before. If a size is too large the image is downsampled with sizeThatFitsKeepingAspectRatio() which preserves the aspect ratio.

+ (DTTextAttachment *)textAttachmentWithElement:(DTHTMLElement *)element options:(NSDictionary *)options

Parameters

element

A DTHTMLElement that must have a valid tag name and should have a size. Any element attributes are copied to the text attachment’s elements.

options

An NSDictionary of options. Used to specify the max image size with the key DTMaxImageSize.

Return Value

Returns the appropriate subclass of the class cluster

Declared In

DTTextAttachment.h

Instance Methods

adjustVerticalAlignmentForFont:

Inspects the given font and records the font’s ascent, descent and leading. These values are then used during layout to properly respond with ascentForLayout, descentForLayout for the receiver’s verticalAlignment.

- (void)adjustVerticalAlignmentForFont:(CTFontRef)font

Parameters

font

The font to inspect

Declared In

DTTextAttachment.h

ascentForLayout

The ascent to use during layout so that the receiver can be display at its verticalAlignment.

- (CGFloat)ascentForLayout

Declared In

DTTextAttachment.h

descentForLayout

The descent to use during layout so that the receiver can be display at its verticalAlignment.

- (CGFloat)descentForLayout

Declared In

DTTextAttachment.h

initWithElement:options:

The designated initializer for members of the DTTextAttachment class cluster. If you need additional setup for custom subclasses then you should override this initializer.

- (id)initWithElement:(DTHTMLElement *)element options:(NSDictionary *)options

Parameters

element

A DTHTMLElement that must have a valid tag name and should have a size. Any element attributes are copied to the text attachment’s elements.

options

An NSDictionary of options. Used to specify the max image size with the key DTMaxImageSize.

Return Value

Returns an initialized DTTextAttachment built using the element and options parameters.

Declared In

DTTextAttachment.h

setDisplaySize:withMaxDisplaySize:

Updates the display size optionally passing a maximum size that it should not exceed.

- (void)setDisplaySize:(CGSize)displaySize withMaxDisplaySize:(CGSize)maxDisplaySize

Parameters

displaySize

The new size to display the content with

maxDisplaySize

the maximum size that the content should be scaled to fit

Discussion

This method in contrast to using the displaySize property will use the originalSize and max display size to calculate missing dimensions.

Declared In

DTTextAttachment.h