DTAttributedTextContentView Class Reference
Inherits from | UIView |
Declared in | DTAttributedTextContentView.h |
Overview
Attributed Text Content Views display attributed strings generated by DTHTMLAttributedStringBuilder. They can display images and hyperlinks inline or optionally place custom subviews (which get provided via the delegate in the appropriate places. By itself content views do not scroll, for that there is the UIScrollView
subclass DTAttributedTextView.
Generally you have two options to providing content:
- set the attributed string
- set a layout frame
The first you would normally use, the second you would use if you are layouting a larger text and then simply want to display individual parts (e.g. pages from an e-book) in a content view.
DTAttributedTextContentView is designed to be used as the content view inside a DTAttributedTextView and thus sizes its intrinsicContentSize always to be the same as the width of the set frame. Use DTAttributedLabel if you don’t require scrolling behavior.
Methods for getting cursor position and frame. Those are convenience methods that call through to the layoutFrame property which has the same coordinate system as the receiver.
You can globally customize the layer class to be used for new instances of CALayer
. For larger bodies of text, i.e. if there is scrolling then you should use a CATiledLayer
subclass instead.
Methods for drawing the content view
Tasks
Sizing
-
– suggestedFrameSizeToFitEntireStringConstraintedToWidth:
-
– intrinsicContentSize
-
layoutFrameHeightIsConstrainedByBounds
property
Layouting
-
– relayoutText
-
layouter
property -
layoutFrame
property
Working with Custom Subviews
Providing Content
-
attributedString
property -
delegate
property
Customizing Content Display
-
edgeInsets
property -
shouldDrawImages
property -
shouldDrawLinks
property -
shouldLayoutCustomSubviews
property -
layoutOffset
property -
backgroundOffset
property -
relayoutMask
property
Cursor Methods
Tiling Methods
Drawing Methods
Properties
attributedString
The attributed string to display in the receiver
@property (nonatomic, copy) NSAttributedString *attributedString
Declared In
DTAttributedTextContentView.h
backgroundOffset
The offset to apply for drawing the background.
@property (nonatomic) CGSize backgroundOffset
Discussion
If you set a pattern color as background color you can have the pattern phase be offset by this value.
Declared In
DTAttributedTextContentView.h
delegate
The delegate that is in charge of supplying custom behavior for the receiver. It must conform to DTAttributedTextContentViewDelegate and provide custom subviews, link buttons, etc.
@property (nonatomic, DT_WEAK_PROPERTY) IBOutlet id<DTAttributedTextContentViewDelegate> delegate
Declared In
DTAttributedTextContentView.h
edgeInsets
The insets to apply around the text content
@property (nonatomic) UIEdgeInsets edgeInsets
Declared In
DTAttributedTextContentView.h
layoutFrame
The layout frame to use for the receiver. Created by default.
@property (atomic, strong) DTCoreTextLayoutFrame *layoutFrame
Discussion
A layout frame is basically one rectangle, inset by the edgeInsets. By default this is automatically generated for the current attributedString. You can also create a DTCoreTextLayoutFrame seperately and set this property to display the layout frame. This is usedful for example if you layout entire e-book and then set the
Declared In
DTAttributedTextContentView.h
layoutFrameHeightIsConstrainedByBounds
Whether the receiver calculates layout limited to the view bounds.
@property (nonatomic, assign) BOOL layoutFrameHeightIsConstrainedByBounds
Discussion
If set to YES
then the layout process calculates the layoutFrame with open ended height. If set to ´NO` then the current bounds of the receiver determine the height.
Declared In
DTAttributedTextContentView.h
layoutOffset
The amount by which all contents of the receiver will offset of display and subview layouting
@property (nonatomic) CGPoint layoutOffset
Declared In
DTAttributedTextContentView.h
layouter
The layouter to use for the receiver. Created by default.
@property (atomic, strong) DTCoreTextLayouter *layouter
Discussion
By default this is generated automatically for the current attributedString. You can also supply your own if you require special layouting behavior.
Declared In
DTAttributedTextContentView.h
relayoutMask
An integer bit mask that determines how the receiver relayouts its contents when its bounds change.
@property (nonatomic) DTAttributedTextContentViewRelayoutMask relayoutMask
Discussion
When the view’s bounds change, that view automatically re-layouts its text according to the relayout mask. You specify the value of this mask by combining the constants described in DTAttributedTextContentViewRelayoutMask using the C bitwise OR operator. Combining these constants lets you specify which dimensions will cause a re-layout if modified. The default value of this property is DTAttributedTextContentViewRelayoutOnWidthChanged, which indicates that the text will be re-layouted if the width changes, but not if the height changes.
Declared In
DTAttributedTextContentView.h
shouldDrawImages
Specifies if the receiver should draw image text attachments.
@property (nonatomic) BOOL shouldDrawImages
Discussion
Set to NO
if you use the delegate methods to provide custom subviews to display images.
Declared In
DTAttributedTextContentView.h
shouldDrawLinks
Specified if the receiver should draw hyperlinks.
@property (nonatomic) BOOL shouldDrawLinks
Discussion
If set to NO
then your custom subview/button for hyperlinks is responsible for displaying hyperlinks. You can use DTLinkButton to have links show a differently for normal and highlighted style
Declared In
DTAttributedTextContentView.h
shouldLayoutCustomSubviews
Specifies if the receiver should layout custom subviews in layoutSubviews.
@property (nonatomic) BOOL shouldLayoutCustomSubviews
Discussion
If set to YES
then all custom subviews will always be layouted. Set to NO
to only layout visible subviews, e.g. in a scroll view. Defaults to YES
if used stand-alone, NO
inside a DTAttributedTextView.
Declared In
DTAttributedTextContentView.h
Class Methods
layerClass
The current layer class that is used for new instances
+ (Class)layerClass
Return Value
The CALayer
subclass that new instances are using
Declared In
DTAttributedTextContentView.h
setLayerClass:
Sets the layer class globally to use in new instances of content views. Defaults to CALayer
.
+ (void)setLayerClass:(Class)layerClass
Parameters
- layerClass
The class to use, should be a
CALayer
subclass
Discussion
While being fine for most use cases you should use a CATiledLayer
subclass for anything larger than a screen full, e.g. in scroll views.
Declared In
DTAttributedTextContentView.h
Instance Methods
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
DTAttributedTextContentView.h
contentImageWithBounds:options:
Creates an image from a part of the receiver’s content view
- (UIImage *)contentImageWithBounds:(CGRect)bounds options:(DTCoreTextLayoutFrameDrawingOptions)options
Parameters
- bounds
The bounds of the content to draw
- options
The drawing options to apply when drawing
Return Value
A UIImage
with the specified content
See Also
[DTCoreTextLayoutFrame drawInContext:options:] for a list of available drawing options
Declared In
DTAttributedTextContentView.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
DTAttributedTextContentView.h
intrinsicContentSize
The size of contents of the receiver. This is possibly used by auto-layout, but also for example if you want to get the size of the receiver necessary for a scroll view
- (CGSize)intrinsicContentSize
Discussion
This method is defined as of iOS 6, but to support earlier OS versions
Declared In
DTAttributedTextContentView.h
layoutSubviewsInRect:
Removes invisible custom subviews and lays out subviews visible in the given rectangle
- (void)layoutSubviewsInRect:(CGRect)rect
Parameters
- rect
The bounds of the visible area to layout custom subviews in.
Declared In
DTAttributedTextContentView.h
relayoutText
Discards the current layoutFrame and creates a new one based on the attributedString.
- (void)relayoutText
Declared In
DTAttributedTextContentView.h
removeAllCustomViews
Removes all custom subviews (excluding views representing links) from the receiver.
- (void)removeAllCustomViews
Declared In
DTAttributedTextContentView.h
removeAllCustomViewsForLinks
Removes all custom subviews representing links from the receiver
- (void)removeAllCustomViewsForLinks
Declared In
DTAttributedTextContentView.h
suggestedFrameSizeToFitEntireStringConstraintedToWidth:
Calculates the suggested frame size that would fit the entire attributedString with a maximum width.
- (CGSize)suggestedFrameSizeToFitEntireStringConstraintedToWidth:(CGFloat)width
Parameters
- width
The maximum width to layout for
Return Value
The suggested frame size
Discussion
This does a full layout pass that is cached in DTCoreTextLayouter. If you specify a frame that fits the result from this method then the resulting layoutFrame is reused.
Since this obeys the edgeInsets you have to add these to the final frame size.
Declared In
DTAttributedTextContentView.h