DTRichTextEditorView Class Reference
| Inherits from | DTAttributedTextView : UIScrollView |
| Conforms to | DTRichTextEditorStandardEditActions UITextInput UITextInputTraits |
| Declared in | DTRichTextEditorView.h |
Overview
DTRichTextEditorView is a subclass of UIScrollView and offers rich text edtiting capabilities. It has a single content view of type DTRichTextEditorContentView which is repsonsible for displaying the rich text.
The Attributes category contains methods to support custom HTML attributes.
The Ranges category enhances DTRichTextEditorView with methods for working with text ranges.
The Dictation category contains methods to support dictation input.
The DTCore Text Category features enhancements for DTRichTextEditorView to interact with DTCoreText internal information.
The Manipulation category enhances DTRichTextEditorView with useful text format manipulation methods.
The Ranges category enhances DTRichTextEditorView with methods for retrieving CSS-like style information.
Tasks
Setting Text Defaults
-
maxImageDisplaySizeproperty -
defaultFontFamilyproperty -
defaultFontSizeproperty -
baseURLproperty -
textSizeMultiplierproperty -
textDefaultsproperty
Accessing the Editor Delegate
-
editorViewDelegateproperty
Accessing Views
Modifying Text Content
Cursor and Selection
Getting Information
-
– boundsOfCurrentSelection -
– visibleBoundsOfCurrentSelection -
canInteractWithPasteboardproperty -
editableproperty -
editingproperty -
replaceParagraphsWithLineFeedsproperty -
attributedTextproperty
Lists Methods
-
– toggleListStyle:inRange: -
– handleNewLineInputInListInRange: -
– updateListsInRange:removeNonPrefixedLinesFromLists:
Attributes Methods
-
– HTMLAttributesAtPosition: -
– rangeOfHTMLAttribute:atPosition: -
– addHTMLAttribute:value:range:replaceExisting: -
– removeHTMLAttribute:range:
Ranges Methods
-
– textRangeOfURLAtPosition:URL: -
– textRangeOfWordAtPosition: -
– textRangeOfParagraphsContainingRange: -
– textRangeOfParagraphContainingPosition:
Dictation Methods
DTCoreText Methods
Manipulation Methods
-
– attributedSubstringForRange: -
– glyphRunAtPosition: -
– plainTextForRange: -
– typingAttributesForRange: -
overrideInsertionAttributesproperty -
– setHTMLString: -
– HTMLStringWithOptions: -
– applyTextAlignment:toParagraphsContainingRange: -
– changeParagraphLeftMarginBy:toParagraphsContainingRange: -
– updateHeaderLevel:inRange: -
– toggleBoldInRange: -
– toggleItalicInRange: -
– toggleUnderlineInRange: -
– toggleStrikethroughInRange: -
– toggleHighlightInRange:color: -
– setForegroundColor:inRange: -
– toggleHyperlinkInRange:URL: -
– updateFontInRange:withFontFamilyName:pointSize: -
– fontDescriptorForRange: -
– setFont: -
– replaceRange:withAttachment:inParagraph: -
– textAttachmentsWithPredicate: -
– pasteboardHasSuitableContentForPaste
Styles Methods
Properties
attributedText
The current attributedText displayed in the receiver
@property (nonatomic, copy) NSAttributedString *attributedTextDeclared In
DTRichTextEditorView.hbaseURL
Override for the base URL.
@property (nonatomic, copy) NSURL *baseURLDiscussion
This property represents part of the textDefaults. Setting those will set this property and vice versa.
Declared In
DTRichTextEditorView.hcanInteractWithPasteboard
Property to enable copy/paste support. If enabled the user can paste text into DTRichTextEditorView or copy text to the pasteboard.
@property (nonatomic, assign) BOOL canInteractWithPasteboardDeclared In
DTRichTextEditorView.hdefaultFontFamily
Override for the default font family.
@property (nonatomic, copy) NSString *defaultFontFamilyDiscussion
This property represents part of the textDefaults. Setting those will set this property and vice versa.
Declared In
DTRichTextEditorView.hdefaultFontSize
Override for the default font size.
@property (nonatomic, assign) CGFloat defaultFontSizeDiscussion
This property represents part of the textDefaults. Setting those will set this property and vice versa.
Declared In
DTRichTextEditorView.heditable
Specifies that the receiver can be edited. That means that on tapping it it becomes first responder and shows the current input view (keyboard). If it is not editable then dragging the finger over the view highlights entire words and does not show the selection dragging handles.
@property (nonatomic, getter=isEditable) BOOL editableDeclared In
DTRichTextEditorView.hediting
Specifies that the receiver is in an editing state. That means that the editor is first responder, and an inputView(usually the system keyboard) and cursor are showing. To programmatically enter an editing state, call becomeFirstResponder on the editor object when isEditable = YES(the default). To programmatically end editing, call resignFirstResponder.
@property (nonatomic, assign, readonly, getter=isEditing) BOOL editingDeclared In
DTRichTextEditorView.heditorViewDelegate
An editor view delegate responds to editing-related messages from the editor view. You can use the delegate to track changes to the text itself and to the current selection.
@property (nonatomic, assign) id<DTRichTextEditorViewDelegate> editorViewDelegateSee Also
Declared In
DTRichTextEditorView.hinputAccessoryView
Overrides the UIResponder input accessory view to be settable. The accessory gets shown riding on top of the inputView when input is possible.
@property (retain, readwrite) UIView *inputAccessoryViewDeclared In
DTRichTextEditorView.hmaxImageDisplaySize
Override for the maximum image display size.
@property (nonatomic, assign) CGSize maxImageDisplaySizeDiscussion
This property represents part of the textDefaults. Setting those will set this property and vice versa.
Declared In
DTRichTextEditorView.hoverrideInsertionAttributes
Temporary storage for typing attributes if there is no range to apply them to, e.g. for a zero-length selection. To retrieve the current typing attributes you should first inspect this property and if it is nil retrieve the typingAttributesForRange: for the current selected text range.
@property (nonatomic, retain) NSDictionary *overrideInsertionAttributesDeclared In
DTRichTextEditorView+Manipulation.hreplaceParagraphsWithLineFeeds
If this property is YES then all typed enters are replaced with the Line Feed (LF) character.
@property (nonatomic, assign) BOOL replaceParagraphsWithLineFeedsDiscussion
Warning: This causes all text to end up in a single paragraph and all paragraph-level styles are going to affect all of the text. It therefore severely affects the display performance. We recommend you don’t activate this if you don’t want spaces between paragraphs but rather set the paragraph spacing to zero via a custom style set via textDefaults.
Declared In
DTRichTextEditorView.htextDefaults
The default options to be used for text. See the options parameter of DTHTMLAttributedStringBuilder for individual options.
@property (nonatomic, retain) NSDictionary *textDefaultsDiscussion
If one of these properties is set then it is used instead of the value contained in textDefaults:
NOTE: Changing these defaults does not affect the current NSAttributedString. They are used when calling setHTMLString.
Declared In
DTRichTextEditorView.htextSizeMultiplier
Override for the text size multiplier.
@property (nonatomic, assign) CGFloat textSizeMultiplierDiscussion
This property represents part of the textDefaults. Setting those will set this property and vice versa.
Declared In
DTRichTextEditorView.hInstance Methods
HTMLAttributesAtPosition:
Retrieves the dictionary of custom HTML attributes active at the given string index
- (NSDictionary *)HTMLAttributesAtPosition:(UITextPosition *)positionParameters
- position
The text position to query
Return Value
The custom HTML attributes dictionary or nil if there aren’t any at this index
Declared In
DTRichTextEditorView+Attributes.hHTMLStringWithOptions:
Converts the current attributed string contents of the receiver to an HTML string.
- (NSString *)HTMLStringWithOptions:(DTHTMLWriterOption)optionsParameters
- options
The options to apply for the conversion.
Return Value
An NSString with a generated HTML representation of the text
Discussion
This uses DTHTMLWriter and uses the currently set textScale to reverse font scale changes. This allows for HTML with a small font size to be displayed at a larger font size, but the generated HTML will still have the original font size.
Valid options are:
- DTHTMLWriterOptionDocument: Styles are compressed into a stylesheet and a header is output (default)
- DTHTMLWriterOptionFragment: All styles are inline and no header is output
Declared In
DTRichTextEditorView+Manipulation.haddHTMLAttribute:value:range:replaceExisting:
Adds the custom HTML attributes with the given value on the given range, optionally replacing occurences of an attribute with the same name.
- (void)addHTMLAttribute:(NSString *)name value:(id)value range:(UITextRange *)range replaceExisting:(BOOL)replaceExistingParameters
- name
The name of the custom HTML attribute
- value
The value to set for the custom attribute
- range
The text range to set the custom attribute on
- replaceExisting
YESif ranges that have an attribute with the same name should be replaced. WithNOthe attribute is only added for ranges where there is no attribute with the given name
Declared In
DTRichTextEditorView+Attributes.happlyTextAlignment:toParagraphsContainingRange:
Applies the given text alignment to all paragraphs that are encompassing the given text range.
- (BOOL)applyTextAlignment:(CTTextAlignment)alignment toParagraphsContainingRange:(UITextRange *)rangeParameters
- alignment
The text alignment to apply
- range
The text range
Return Value
YES if at least one paragraph’s alignment was changed
Declared In
DTRichTextEditorView+Manipulation.hattributedStringAttributesForTextDefaults
Determines the Core Text attributes for the text defaults currently set on the receiver.
- (NSDictionary *)attributedStringAttributesForTextDefaultsReturn Value
An attribute dictionary suitable for constructing default text
Declared In
DTRichTextEditorView+Styles.hattributedSubstringForRange:
Retrieves that attributed substring for the given range.
- (NSAttributedString *)attributedSubstringForRange:(UITextRange *)rangeParameters
- range
The text range
Return Value
The NSAttributedString substring
Declared In
DTRichTextEditorView+Manipulation.hattributesForTagName:tagClass:tagIdentifier:relativeToTextSize:
Retrieves the NSAttributedString attributes for a given tag name, considering overrides specified via textDefaults
- (NSDictionary *)attributesForTagName:(NSString *)tagName tagClass:(NSString *)tagClass tagIdentifier:(NSString *)tagIdentifier relativeToTextSize:(CGFloat)textSizeParameters
- tagName
The tag name to retrieve a attributes for
- tagClass
The tag class, or
nil
- tagIdentifier
The tag id or
nil
- textSize
The text size to use for relative measurements
Return Value
The attributes dictionary
Discussion
The relativeToTextSize is needed because some styles sizings depend on the current text size, e.g. 0.8em
Declared In
DTRichTextEditorView+Styles.hboundsOfCurrentSelection
Gets the bounds of the rectangle that encloses the cursor or an envelope around the current selection. Can be used for the target area of a context menu.
- (CGRect)boundsOfCurrentSelectionDeclared In
DTRichTextEditorView.hchangeParagraphLeftMarginBy:toParagraphsContainingRange:
Changes the paragraph indentation by the given amount.
- (void)changeParagraphLeftMarginBy:(CGFloat)delta toParagraphsContainingRange:(UITextRange *)rangeParameters
- delta
The amont to modify the left indentation by.
- range
The text range
Discussion
This modifies both the firstLineHeadIndent as well as the headIndent properties of the paragraph styles.
Declared In
DTRichTextEditorView+Manipulation.hdefaultFontDescriptor
Retrieves a font descriptor for the default font, considering overrides specified via textDefaults
- (DTCoreTextFontDescriptor *)defaultFontDescriptorReturn Value
A font descriptor
Declared In
DTRichTextEditorView+Styles.hdictationPlaceholderAtPosition:
Convenience method to retrieve the placeholder object at the given position.
- (DTDictationPlaceholderTextAttachment *)dictationPlaceholderAtPosition:(UITextPosition *)positionParameters
- position
The text position to retrieve the placeholder from
Return Value
The dictation placeholder or nil if there is none at the given text position.
Declared In
DTRichTextEditorView+Dictation.hfontDescriptorForRange:
Returns a font descriptor that matches the font at the given range. The method calls typingAttributesForRange: and converts the font to a font descriptor. If the range is empty then the font matches what it would be if the user would start typing. If the range is not empty then it is the font of the first character in the range.
- (DTCoreTextFontDescriptor *)fontDescriptorForRange:(UITextRange *)rangeParameters
- range
The text range in the attributed string for which to query the font
Return Value
The font descriptor
Declared In
DTRichTextEditorView+Manipulation.hglyphRunAtPosition:
Retrieves the glyph run around the given text location. This is useful to inspect the actually used attributes. For example you can get the actual writing direction or the actually used font used.
- (DTCoreTextGlyphRun *)glyphRunAtPosition:(UITextPosition *)positionParameters
- position
The text position
Return Value
The DTCoreTextGlyphRun object with all glyphs having the same attributes
Declared In
DTRichTextEditorView+Manipulation.hhandleNewLineInputInListInRange:
Handles the following scenarios of entering a New Line character inside a list block.
- (BOOL)handleNewLineInputInListInRange:(UITextRange *)rangeParameters
- range
The text range of the selection
Return Value
YES if the range started inside a list
Discussion
- NL at beginning of an empty paragraph at end of list: toggles off the list for this paragraph
- NL at end of non-empty paragraph: extends the list to the new paragraph
- NL in some other paragraph of the list: inserts a new list paragraph inside the list
Declared In
DTRichTextEditorView+Lists.hlayoutLineAtIndex:
Returns the layout line at the given string index
- (DTCoreTextLayoutLine *)layoutLineAtIndex:(NSUInteger)lineIndexParameters
- lineIndex
The index of the line
Return Value
the layout line
Declared In
DTRichTextEditorView+DTCoreText.hlayoutLineContainingTextPosition:
Returns the layout line that contains the given text position.
- (DTCoreTextLayoutLine *)layoutLineContainingTextPosition:(UITextPosition *)textPositionParameters
- textPosition
The text position
Return Value
the layout line
Declared In
DTRichTextEditorView+DTCoreText.hlistIndentForListStyle:
Retrieves the list indent from the leading margin to apply for a given list style
- (CGFloat)listIndentForListStyle:(DTCSSListStyle *)listStyleParameters
- listStyle
The CSS list style to determine the list indentation for
Return Value
The indent or 0 if listStyle is nil
Discussion
This value is determined by parsing a single character HTML with the appropriate list HTML and takes the textDefaults into consideration.
Declared In
DTRichTextEditorView+Styles.hnumberOfLayoutLines
The number of text lines in the receiver.
- (NSUInteger)numberOfLayoutLinesReturn Value
The number of text lines in the receiver.
Declared In
DTRichTextEditorView+DTCoreText.hpasteboardHasSuitableContentForPaste
Determines if there is something on the pasteboard that can be pasted into the receiver.
- (BOOL)pasteboardHasSuitableContentForPasteReturn Value
YES if something can be pasted
Declared In
DTRichTextEditorView+Manipulation.hplainTextForRange:
Prepares a plain-text representation of the substring for the given range.
- (NSString *)plainTextForRange:(UITextRange *)rangeParameters
- range
The text range.
Return Value
A substring of the receivers current contents
Discussion
If the attributed string in this range contains attachments then those are removed.
Declared In
DTRichTextEditorView+Manipulation.hrangeOfHTMLAttribute:atPosition:
Retrieves the range that an attribute with a given name is active for, beginning with the passed index
- (NSRange)rangeOfHTMLAttribute:(NSString *)name atPosition:(UITextPosition *)positionParameters
- name
The name of the custom HTML attribute to query
- position
The text position to query
Return Value
The custom HTML attributes dictionary or nil if there aren’t any at this index
Discussion
Since a custom HTML attribute can occur in multiple individual attribute dictionaries this extends the range from the passed index outwards until the full range of the custom HTML attribute has been found. Those range extentions have to have an identical value, as established by comparing them to the value of the custom attribute at the index with isEqual:
Declared In
DTRichTextEditorView+Attributes.hremoveHTMLAttribute:range:
Adds the custom HTML attributes with the given value from the given range.
- (void)removeHTMLAttribute:(NSString *)name range:(UITextRange *)rangeParameters
- name
The name of the custom HTML attribute
- range
The text range to remove the custom attribute from
Declared In
DTRichTextEditorView+Attributes.hreplaceRange:withAttachment:inParagraph:
Inserts an attachment in the given text range.
- (void)replaceRange:(UITextRange *)range withAttachment:(DTTextAttachment *)attachment inParagraph:(BOOL)inParagraphParameters
- range
The text range for the insertion
- attachment
The text attachment to be inserted
- inParagraph
If
YESthen the method makes sure that the attachment sits in its own paragraph
Declared In
DTRichTextEditorView+Manipulation.hreplaceRange:withText:
Replaces a range of text. The current selection is adapted, too.
- (void)replaceRange:(UITextRange *)range withText:(id)textParameters
- range
The text range to replace
- text
The text for the replacement
Discussion
This is an overwritten method that accepts either an NSString or NSAttributedString.
Declared In
DTRichTextEditorView.hscrollCursorVisibleAnimated:
Scrolls the receiver’s content view so that the cursor is visible.
- (void)scrollCursorVisibleAnimated:(BOOL)animatedParameters
- animated
If
YESthen the view is scrolled animated. IfNOit jumps to the scroll position
Declared In
DTRichTextEditorView.hsetFont:
Convenience method to set the defaultFontFamily and defaultFontSize to the given font’s values. Updates the entire string with this.
- (void)setFont:(UIFont *)fontParameters
- font
The font to use the values from
Declared In
DTRichTextEditorView+Manipulation.hsetForegroundColor:inRange:
Sets the text foreground color for a given range.
- (void)setForegroundColor:(UIColor *)color inRange:(UITextRange *)rangeParameters
- color
The foreground color to set. Passing
nilremoves the color attribute and thus restores the black default color.
- range
The text range
Declared In
DTRichTextEditorView+Manipulation.hsetHTMLString:
Converts the given string to an NSAttributedString using the current textDefaults and sets it on the receiver.
- (void)setHTMLString:(NSString *)stringParameters
- string
The string containing HTML text to convert to an attributed string and set as content of the receiver
Declared In
DTRichTextEditorView+Manipulation.hsetInputView:animated:
Sets the input view which will be shown instead of the keyboard. If the receiver already has first responder then this replaces the previous input view or standard keyboard. If the receiver is not first responder, then the animated parameter will be ignored
- (void)setInputView:(UIView *)inputView animated:(BOOL)animatedParameters
- inputView
The new input view to set on the receiver, or ‘nil’ to restore the keyboard
- animated
Whether the replacement should be animated
Declared In
DTRichTextEditorView.hsetSelectedTextRange:animated:
Changes the current text selection range to the new value. Can optionally be animated.
- (void)setSelectedTextRange:(DTTextRange *)newTextRange animated:(BOOL)animatedParameters
- newTextRange
The new text range to select
- animated
If
YESthen an extension (e.g. to include a full word) is animated
Declared In
DTRichTextEditorView.htextAttachmentsWithPredicate:
Retrieving the attachments that match a predicate.
- (NSArray *)textAttachmentsWithPredicate:(NSPredicate *)predicateParameters
- predicate
The
NSPredicatethat will be used to check the DTTextAttachment key values against
Return Value
An array of matching attachments
Declared In
DTRichTextEditorView+Manipulation.htextRangeOfDictationPlaceholder
Retrieves the range of the first dictation placeholder in the text.
- (UITextRange *)textRangeOfDictationPlaceholderReturn Value
The selection range
Discussion
You can use this to replace the dictation placeholder with the recognized text.
Declared In
DTRichTextEditorView+Dictation.htextRangeOfParagraphContainingPosition:
Finds the text range that includes the given cursor position.
- (UITextRange *)textRangeOfParagraphContainingPosition:(UITextPosition *)positionParameters
- position
The cursor position
Return Value
The paragraph range
Declared In
DTRichTextEditorView+Ranges.htextRangeOfParagraphsContainingRange:
Extends the given range to include all full paragraphs that contain it.
- (UITextRange *)textRangeOfParagraphsContainingRange:(UITextRange *)rangeParameters
- range
The text range
Return Value
The extended range
Declared In
DTRichTextEditorView+Ranges.htextRangeOfURLAtPosition:URL:
Gets the text range of an URL at the given text position. Optionally also returns the hyperlink URL.
- (UITextRange *)textRangeOfURLAtPosition:(UITextPosition *)position URL:(NSURL **)URLParameters
- position
The text position
- URL
An optional URL output param or
NULLif the URL is not required
Return Value
the text range or NULL if there is no URL at this position
Declared In
DTRichTextEditorView+Ranges.htextRangeOfWordAtPosition:
Gets the range that encompasses the word at the given text position.
- (UITextRange *)textRangeOfWordAtPosition:(UITextPosition *)positionParameters
- position
The text position
Return Value
the text range
Declared In
DTRichTextEditorView+Ranges.htoggleBoldInRange:
Toggles bold font style on the given range.
- (void)toggleBoldInRange:(UITextRange *)rangeParameters
- range
The text range
Discussion
The first character of the range determines if the range is to be treated as bold or not.
Declared In
DTRichTextEditorView+Manipulation.htoggleHighlightInRange:color:
Highlights a given range.
- (void)toggleHighlightInRange:(UITextRange *)range color:(UIColor *)colorParameters
- range
The text range
- color
The highlight color to mark the range with. If the range is already marked then this parameter is ignored.
Discussion
The first character of the range determines if the range is to be treated as already highlighted or not.
Declared In
DTRichTextEditorView+Manipulation.htoggleHyperlinkInRange:URL:
Toggles a hyperlink on the given range.
- (void)toggleHyperlinkInRange:(UITextRange *)range URL:(NSURL *)URLParameters
- range
The text range
- URL
The hyperlink URL to set on the range with. If the range already has a hyperlink then this parameter is ignored.
Discussion
The first character of the range determines if the range is to be treated as already hyperlinked or not.
Declared In
DTRichTextEditorView+Manipulation.htoggleItalicInRange:
Toggles italic font style on the given range.
- (void)toggleItalicInRange:(UITextRange *)rangeParameters
- range
The text range
Discussion
The first character of the range determines if the range is to be treated as italic or not.
Declared In
DTRichTextEditorView+Manipulation.htoggleListStyle:inRange:
Toggles a list style on a given range.
- (void)toggleListStyle:(DTCSSListStyle *)listStyle inRange:(UITextRange *)rangeParameters
- listStyle
the list style to toggle, or
nilto remove the list style.
- range
The text range
Discussion
Toggling the list style is its own Undo group unless you set _keepCurrentUndoGroup to YES.
Declared In
DTRichTextEditorView+Lists.htoggleStrikethroughInRange:
Toggles strikethrough font style on the given range.
- (void)toggleStrikethroughInRange:(UITextRange *)rangeParameters
- range
The text range
Discussion
The first character of the range determines if the range is to be treated as strikethrough or not.
Declared In
DTRichTextEditorView+Manipulation.htoggleUnderlineInRange:
Toggles underline font style on the given range.
- (void)toggleUnderlineInRange:(UITextRange *)rangeParameters
- range
The text range
Discussion
The first character of the range determines if the range is to be treated as underlined or not.
Declared In
DTRichTextEditorView+Manipulation.htypingAttributesForRange:
The attributes to apply for new text inserted at the given range.
- (NSDictionary *)typingAttributesForRange:(UITextRange *)rangeParameters
- range
The text range
Return Value
The dictionary of styles
Declared In
DTRichTextEditorView+Manipulation.hupdateFontInRange:withFontFamilyName:pointSize:
Replaces the font for a given range preserving bold or italic ranges.
- (void)updateFontInRange:(UITextRange *)range withFontFamilyName:(NSString *)fontFamilyName pointSize:(CGFloat)pointSizeParameters
- range
The text range
- fontFamilyName
The postscript font family name, or
nilif the font family should be preserved.
- pointSize
The point size in pixels to apply, or 0 if it should be preserved
Declared In
DTRichTextEditorView+Manipulation.hupdateHeaderLevel:inRange:
Apples a given header level to the given range. The range is extended to include full paragraphs.
- (void)updateHeaderLevel:(NSUInteger)headerLevel inRange:(UITextRange *)rangeParameters
- headerLevel
The header level (1-6) to set or 0 to restore normal paragraph style
- range
The text range
Discussion
If the range belongs to a list then it is removed from the list. All existing attributes are replaced.
Declared In
DTRichTextEditorView+Manipulation.hupdateListsInRange:removeNonPrefixedLinesFromLists:
Updates lists (prefixes and spacing) intersecting with the given range
- (void)updateListsInRange:(UITextRange *)range removeNonPrefixedLinesFromLists:(BOOL)removeNonPrefixedParameters
- range
The text range to update
- removeNonPrefixed
Whether lines that don’t posess a prefix should be removed from lists
Declared In
DTRichTextEditorView+Lists.h