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 -
layoutFrameHeightIsConstrainedByBoundsproperty
Layouting
-
– relayoutText -
layouterproperty -
layoutFrameproperty
Working with Custom Subviews
Providing Content
-
attributedStringproperty -
delegateproperty
Customizing Content Display
-
edgeInsetsproperty -
shouldDrawImagesproperty -
shouldDrawLinksproperty -
shouldLayoutCustomSubviewsproperty -
layoutOffsetproperty -
backgroundOffsetproperty -
relayoutMaskproperty
Cursor Methods
Tiling Methods
Drawing Methods
Properties
attributedString
The attributed string to display in the receiver
@property (nonatomic, copy) NSAttributedString *attributedStringDeclared In
DTAttributedTextContentView.hbackgroundOffset
The offset to apply for drawing the background.
@property (nonatomic) CGSize backgroundOffsetDiscussion
If you set a pattern color as background color you can have the pattern phase be offset by this value.
Declared In
DTAttributedTextContentView.hdelegate
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> delegateDeclared In
DTAttributedTextContentView.hedgeInsets
The insets to apply around the text content
@property (nonatomic) UIEdgeInsets edgeInsetsDeclared In
DTAttributedTextContentView.hlayoutFrame
The layout frame to use for the receiver. Created by default.
@property (atomic, strong) DTCoreTextLayoutFrame *layoutFrameDiscussion
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.hlayoutFrameHeightIsConstrainedByBounds
Whether the receiver calculates layout limited to the view bounds.
@property (nonatomic, assign) BOOL layoutFrameHeightIsConstrainedByBoundsDiscussion
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.hlayoutOffset
The amount by which all contents of the receiver will offset of display and subview layouting
@property (nonatomic) CGPoint layoutOffsetDeclared In
DTAttributedTextContentView.hlayouter
The layouter to use for the receiver. Created by default.
@property (atomic, strong) DTCoreTextLayouter *layouterDiscussion
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.hrelayoutMask
An integer bit mask that determines how the receiver relayouts its contents when its bounds change.
@property (nonatomic) DTAttributedTextContentViewRelayoutMask relayoutMaskDiscussion
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.hshouldDrawImages
Specifies if the receiver should draw image text attachments.
@property (nonatomic) BOOL shouldDrawImagesDiscussion
Set to NO if you use the delegate methods to provide custom subviews to display images.
Declared In
DTAttributedTextContentView.hshouldDrawLinks
Specified if the receiver should draw hyperlinks.
@property (nonatomic) BOOL shouldDrawLinksDiscussion
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.hshouldLayoutCustomSubviews
Specifies if the receiver should layout custom subviews in layoutSubviews.
@property (nonatomic) BOOL shouldLayoutCustomSubviewsDiscussion
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.hClass Methods
layerClass
The current layer class that is used for new instances
+ (Class)layerClassReturn Value
The CALayer subclass that new instances are using
Declared In
DTAttributedTextContentView.hsetLayerClass:
Sets the layer class globally to use in new instances of content views. Defaults to CALayer.
+ (void)setLayerClass:(Class)layerClassParameters
- layerClass
The class to use, should be a
CALayersubclass
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.hInstance Methods
closestCursorIndexToPoint:
Determines the closest string index to a point in the receiver’s frame.
- (NSInteger)closestCursorIndexToPoint:(CGPoint)pointParameters
- 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.hcontentImageWithBounds:options:
Creates an image from a part of the receiver’s content view
- (UIImage *)contentImageWithBounds:(CGRect)bounds options:(DTCoreTextLayoutFrameDrawingOptions)optionsParameters
- 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.hcursorRectAtIndex:
The rectangle to draw a caret for a given index
- (CGRect)cursorRectAtIndex:(NSInteger)indexParameters
- index
The string index for which to determine a cursor frame
Return Value
The cursor rectangle
Declared In
DTAttributedTextContentView.hintrinsicContentSize
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)intrinsicContentSizeDiscussion
This method is defined as of iOS 6, but to support earlier OS versions
Declared In
DTAttributedTextContentView.hlayoutSubviewsInRect:
Removes invisible custom subviews and lays out subviews visible in the given rectangle
- (void)layoutSubviewsInRect:(CGRect)rectParameters
- rect
The bounds of the visible area to layout custom subviews in.
Declared In
DTAttributedTextContentView.hrelayoutText
Discards the current layoutFrame and creates a new one based on the attributedString.
- (void)relayoutTextDeclared In
DTAttributedTextContentView.hremoveAllCustomViews
Removes all custom subviews (excluding views representing links) from the receiver.
- (void)removeAllCustomViewsDeclared In
DTAttributedTextContentView.hremoveAllCustomViewsForLinks
Removes all custom subviews representing links from the receiver
- (void)removeAllCustomViewsForLinksDeclared In
DTAttributedTextContentView.hsuggestedFrameSizeToFitEntireStringConstraintedToWidth:
Calculates the suggested frame size that would fit the entire attributedString with a maximum width.
- (CGSize)suggestedFrameSizeToFitEntireStringConstraintedToWidth:(CGFloat)widthParameters
- 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