DTAttributedTextView Class Reference
Inherits from | UIScrollView |
Declared in | DTAttributedTextView.h |
Overview
This view is designed to be a replacement for UITextView
. It is a UIScrollView
subclass and creates a DTAttributedTextContentView as content view for displaying the text.
The content view of type DTAttributedTextContentView is created lazily. You should not set values on it directly if you use it in conjunction with this class for scrolling.
Tasks
Providing Content
-
attributedString
property -
textDelegate
property -
– relayoutText
Accessing Subviews
-
attributedTextContentView
property -
backgroundView
property
Customizing Display
-
shouldDrawLinks
property -
shouldDrawImages
property
Customizing Content View
User Interaction
Working with a Cursor
Properties
attributedString
The attributed text to be displayed in the text content view of the receiver.
@property (nonatomic, strong) NSAttributedString *attributedString
Declared In
DTAttributedTextView.h
attributedTextContentView
References to the DTAttributedTextContentView that display the text. This is not named contentView because this class inherits from UIScrollView
which has an internal property of this name
@property (nonatomic, strong, readonly) DTAttributedTextContentView *attributedTextContentView
Declared In
DTAttributedTextView.h
backgroundView
A view to be displayed behind the text content view
@property (nonatomic, strong) IBOutlet UIView *backgroundView
Declared In
DTAttributedTextView.h
shouldDrawImages
If the content view of the receiver should draw images. Set to NO
if displaying images as custom views via textDelegate;
@property (nonatomic, assign) BOOL shouldDrawImages
Discussion
Defaults to YES
if you supply your own image drawing then set this property to NO and supply your custom image view (e.g. DTLazyImageView) via the textDelegate.
Declared In
DTAttributedTextView.h
shouldDrawLinks
If the content view of the receiver should draw links. Set to NO
if displaying links as custom views via textDelegate;
@property (nonatomic, assign) BOOL shouldDrawLinks
Discussion
Defaults to YES
if you supply your own link drawing then set this property to NO and supply your custom view (e.g. DTLinkButton) via the textDelegate.
Declared In
DTAttributedTextView.h
textDelegate
A delegate implementing DTAttributedTextContentViewDelegate to provide custom subviews for images and links.
@property (nonatomic, DT_WEAK_PROPERTY) IBOutlet id<DTAttributedTextContentViewDelegate> textDelegate
Declared In
DTAttributedTextView.h
Instance Methods
classForContentView
You can override this method to provide a different class to use for the content view. If you replace the content view class then it should inherit from DTAttributedTextContentView which is also the default.
- (Class)classForContentView
Return Value
The class to use for the content view.
Declared In
DTAttributedTextView.h
closestCursorIndexToPoint:
Determines the closest string index to a point in the receiver’s frame.
- (NSInteger)closestCursorIndexToPoint:(CGPoint)point
Parameters
- point
The point
Return Value
The resulting string index
Discussion
This can be used to find the cursor position to position an input caret at.
Declared In
DTAttributedTextView.h
cursorRectAtIndex:
The rectangle to draw a caret for a given index
- (CGRect)cursorRectAtIndex:(NSInteger)index
Parameters
- index
The string index for which to determine a cursor frame
Return Value
The cursor rectangle
Declared In
DTAttributedTextView.h
relayoutText
Performs a new layout pass on the receiver. This destroys the frame setter, calls relayoutText on the content view and marks the receiver as needing layout so that custom subviews get appropriately sized.
- (void)relayoutText
Declared In
DTAttributedTextView.h
scrollRangeToVisible:animated:
Scrolls the receiver until the text in the specified range is visible.
- (void)scrollRangeToVisible:(NSRange)range animated:(BOOL)animated
Parameters
- range
The range of text to scroll into view.
- animated
YES
if the movement should be animated.
Declared In
DTAttributedTextView.h
scrollToAnchorNamed:animated:
Scrolls the receiver to the anchor with the given name to the top.
- (void)scrollToAnchorNamed:(NSString *)anchorName animated:(BOOL)animated
Parameters
- anchorName
The name of the href anchor.
- animated
YES
if the movement should be animated.
Declared In
DTAttributedTextView.h