NimbusKit
1.2.1 - Fork Nimbus on Github - Visit the Nimbus Wiki
The iOS framework that grows only as fast as its documentation
|
The NIAttributedLabel class provides support for displaying rich text with selectable links and embedded images.
Differences between UILabel and NIAttributedLabel:
NSLineBreakByTruncatingHead
and NSLineBreakByTruncatingMiddle
only apply to single lines and will not wrap the label regardless of the numberOfLines
property. To wrap lines with any of these line break modes you must explicitly add newline characters to the string.NIAttributedLabel implements the UIAccessibilityContainer methods to expose each link as an accessibility item.
Tasks | |
Accessing the Text Attributes | |
NSAttributedString * | attributedString property |
Accessing and Detecting Links | |
BOOL | autoDetectLinks property |
NSTextCheckingType | dataDetectorTypes property |
BOOL | deferLinkDetection property |
(void) | - addLink:range: |
(void) | - removeAllExplicitLinks |
Accessing Link Display Styles | |
UIColor * | linkColor property |
UIColor * | highlightedLinkBackgroundColor property |
BOOL | linksHaveUnderlines property |
NSDictionary * | attributesForLinks property |
NSDictionary * | attributesForHighlightedLink property |
Modifying Rich Text Styles for All Text | |
CGFloat | lineHeight property |
NIVerticalTextAlignment | verticalTextAlignment property |
CTUnderlineStyle | underlineStyle property |
CTUnderlineStyleModifiers | underlineStyleModifier property |
CGFloat | shadowBlur property |
CGFloat | strokeWidth property |
UIColor * | strokeColor property |
CGFloat | textKern property |
Modifying Tail Truncation Properties | |
NSString * | tailTruncationString property |
Accessing the Delegate | |
IBOutlet id < NIAttributedLabelDelegate > | delegate property |
Modifying Rich Text Styles in Ranges | |
(void) | - setFont:range: |
(void) | - setStrokeColor:range: |
(void) | - setStrokeWidth:range: |
(void) | - setTextColor:range: |
(void) | - setTextKern:range: |
(void) | - setUnderlineStyle:modifier:range: |
Adding Inline Images | |
(void) | - insertImage:atIndex: |
(void) | - insertImage:atIndex:margins: |
(void) | - insertImage:atIndex:margins:verticalTextAlignment: |
Accessibility | |
(void) | - invalidateAccessibleElements |
This method is now deprecated and will eventually be removed, please use attributedText instead.
A Booelan value indicating whether to automatically detect links in the string.
By default this is disabled.
Link detection is deferred until the label is displayed for the first time. If the text changes then all of the links will be cleared and re-detected when the label displays again.
Note that link detection is an expensive operation. If you are planning to use attributed labels in table views or similar high-performance situations then you should consider enabling defered link detection by setting deferLinkDetection to YES.
The types of data that will be detected when autoDetectLinks is enabled.
By default this is NSTextCheckingTypeLink. All available data detector types.
A Boolean value indicating whether to defer link detection to a separate thread.
By default this is disabled.
When defering is enabled, link detection will be performed on a separate thread. This will cause your label to appear without any links briefly before being redrawn with the detected links. This offloads the data detection to a separate thread so that your labels can be displayed faster.
The text color of detected links.
The default color is [UIColor blueColor] on pre-iOS 7 devices or self.tintColor on iOS 7 devices. If linkColor is assigned nil then links will not be given any special color. Use attributesForLinks to specify alternative styling.
The background color of the link's selection frame when the user is touching the link.
The default is [UIColor colorWithWhite:0.5 alpha:0.5].
If you do not want links to be highlighted when touched, set this to nil.
A Boolean value indicating whether links should have underlines.
By default this is disabled.
This affects all links in the label.
A dictionary of CoreText attributes to apply to links.
This dictionary must contain CoreText attributes. These attributes are applied after the color and underline styles have been applied to the link.
A dictionary of CoreText attributes to apply to the highlighted link.
This dictionary must contain CoreText attributes. These attributes are applied after attributesForLinks have been applied to the highlighted link.
Sets the line height for the text.
By default this is zero.
Setting this value to zero will make the label use the default line height for the text's font.
The vertical alignment of the text within the label's bounds.
The default is NIVerticalTextAlignmentTop
. This is for performance reasons because the other modes require more computation. Aligning to the top is generally what you want anyway.
NIVerticalTextAlignmentBottom
will align the text to the bottom of the bounds, while NIVerticalTextAlignmentMiddle
will center the text vertically.
The underline style for the entire label.
By default this is kCTUnderlineStyleNone
.
The underline style modifier for the entire label.
By default this is kCTUnderlinePatternSolid
.
A non-negative number specifying the amount of blur to apply to the label's text shadow.
By default this is zero.
Sets the stroke width for the text.
By default this is zero.
Positive numbers will draw the stroke. Negative numbers will draw the stroke and fill.
Sets the stroke color for the text.
By default this is nil.
Sets the kern for the text.
By default this is zero.
The text kern indicates how many points each character should be shifted from its default offset. A positive kern indicates a shift farther away. A negative kern indicates a shift closer.
The string to display for tail truncation.
By default this is nil and the default ellipses character, , is used.
The delegate of the attributed-label object.
The delegate must adopt the NIAttributedLabelDelegate protocol. The NIAttributedLabel class, which does not strong the delegate, invokes each protocol method the delegate implements.
Adds a link to a URL at a given range.
Adding any links will immediately enable user interaction on this label. Explicitly added links are removed whenever the text changes.
Removes all explicit links from the label.
If you wish to remove automatically-detected links, set autoDetectLinks to NO.
Sets the font for text in a given range.
Sets the stroke color for text in a given range.
Sets the stroke width for text in a given range.
Positive numbers will draw the stroke. Negative numbers will draw the stroke and fill.
Sets the text color for text in a given range.
Sets the kern for text in a given range.
The text kern indicates how many points each character should be shifted from its default offset. A positive kern indicates a shift farther away. A negative kern indicates a shift closer.
Sets the underline style and modifier for text in a given range.
Inserts the given image inline at the given index in the receiver's text.
The image will have no margins. The image's vertical text alignment will be NIVerticalTextAlignmentBottom.
image | The image to add to the receiver. |
index | The index into the receiver's text at which to insert the image. |
Inserts the given image inline at the given index in the receiver's text.
The image's vertical text alignment will be NIVerticalTextAlignmentBottom.
image | The image to add to the receiver. |
index | The index into the receiver's text at which to insert the image. |
margins | The space around the image on all sides in points. |
Inserts the given image inline at the given index in the receiver's text.
image | The image to add to the receiver. |
index | The index into the receiver's text at which to insert the image. |
margins | The space around the image on all sides in points. |
verticalTextAlignment | The position of the text relative to the image. |
Invalidates this label's accessible elements.
When a label is contained within another view and that parent view moves, the label will not be informed of this change and any existing accessibility elements will still point to the old screen location. If this happens you must call -invalidateAccessibleElements in order to force the label to refresh its accessibile elements.