NSAttributedString(DTCoreText) Category Reference
Declared in | NSAttributedString+DTCoreText.h |
Tasks
Working with Text Attachments
Calculating Ranges
-
– itemNumberInTextList:atIndex:
-
– rangeOfTextList:atIndex:
-
– rangeOfTextBlock:atIndex:
-
– rangeOfAnchorNamed:
-
– rangeOfLinkAtIndex:URL:
-
– rangeOfFieldAtIndex:
Converting to Other Representations
Creating Special Attributed Strings
Class Methods
prefixForListItemWithCounter:listStyle:listIndent:attributes:
Create a prefix for a paragraph in a list
+ (NSAttributedString *)prefixForListItemWithCounter:(NSUInteger)listCounter listStyle:(DTCSSListStyle *)listStyle listIndent:(CGFloat)listIndent attributes:(NSDictionary *)attributes
Parameters
- listCounter
The value for the list item.
- listStyle
The list style
- listIndent
The amount in px to indent the list
- attributes
The attribute dictionary for the text to be prefixed
Return Value
An attributed string with the list prefix
Declared In
NSAttributedString+DTCoreText.h
Instance Methods
htmlFragment
Encodes the receiver into a generic HTML fragment representation. Styles are inlined and no html or head tags are included.
- (NSString *)htmlFragment
Return Value
An HTML string.
Declared In
NSAttributedString+DTCoreText.h
htmlString
Encodes the receiver into a generic HTML prepresentation.
- (NSString *)htmlString
Return Value
An HTML string.
Declared In
NSAttributedString+DTCoreText.h
itemNumberInTextList:atIndex:
Returns the index of the item at the given location within the list.
- (NSInteger)itemNumberInTextList:(DTCSSListStyle *)list atIndex:(NSUInteger)location
Parameters
- list
The text list.
- location
The location of the item.
Return Value
Returns the index within the list.
Declared In
NSAttributedString+DTCoreText.h
plainTextString
Converts the receiver into plain text.
- (NSString *)plainTextString
Return Value
The receiver converted to plain text.
Discussion
This is different from the string
method of NSAttributedString
by also erasing placeholders for text attachments.
Declared In
NSAttributedString+DTCoreText.h
rangeOfAnchorNamed:
Returns the range of the given href anchor.
- (NSRange)rangeOfAnchorNamed:(NSString *)anchorName
Parameters
- anchorName
The name of the anchor.
Return Value
The range of the given anchor.
Declared In
NSAttributedString+DTCoreText.h
rangeOfFieldAtIndex:
Returns the range of a field at the given index.
- (NSRange)rangeOfFieldAtIndex:(NSUInteger)location
Parameters
- location
The location of the field
Return Value
The range of the field. If there is no field at this location it returns {NSNotFound, 0}.
Declared In
NSAttributedString+DTCoreText.h
rangeOfLinkAtIndex:URL:
Returns the range of the hyperlink at the given index.
- (NSRange)rangeOfLinkAtIndex:(NSUInteger)location URL:(NSURL *__autoreleasing *)URL
Parameters
- location
The location to query
- URL
The URL that is found at this location or
NULL
if this is not needed
Return Value
The range of the given hyperlink.
Declared In
NSAttributedString+DTCoreText.h
rangeOfTextBlock:atIndex:
Returns the range of the given text block that contains the given location.
- (NSRange)rangeOfTextBlock:(DTTextBlock *)textBlock atIndex:(NSUInteger)location
Parameters
- textBlock
The text block.
- location
The location in the text.
Return Value
The range of the given text block containing the location.
Declared In
NSAttributedString+DTCoreText.h
rangeOfTextList:atIndex:
Returns the range of the given text list that contains the given location.
- (NSRange)rangeOfTextList:(DTCSSListStyle *)list atIndex:(NSUInteger)location
Parameters
- list
The text list.
- location
The location in the text.
Return Value
The range of the given text list containing the location.
Declared In
NSAttributedString+DTCoreText.h
textAttachmentsWithPredicate:class:
Retrieves the DTTextAttachment objects that match the given predicate.
- (NSArray *)textAttachmentsWithPredicate:(NSPredicate *)predicate class:(Class)theClass
Parameters
- predicate
The predicate to apply for filtering or
nil
to not filter by attachment
- theClass
The class that attachments need to have, or
nil
for all attachments regardless of class
Return Value
The filtered array of attachments
Discussion
With this method you can for example find all images that have a certain URL.
Declared In
NSAttributedString+DTCoreText.h