Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
[attributedlabel] Standardize property names. Full passthrough of docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
jverkoey committed Jun 18, 2012
1 parent 8c47f78 commit 6e5c685
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 175 deletions.
Expand Up @@ -61,7 +61,7 @@ - (void)viewDidLoad {

// Turn on all available data detectors. This includes phone numbers, email addresses, and
// addresses.
label.dataTypes = NSTextCheckingAllSystemTypes;
label.dataDetectorTypes = NSTextCheckingAllSystemTypes;

label.text = @"She presses a button next to the display and it flickers once more."
@"\n\nUpon the arrival at Gliese 581 g, initiate contact with the following:"
Expand Down
Expand Up @@ -68,7 +68,7 @@ - (void)viewDidLoad {
self.label.lineBreakMode = UILineBreakModeWordWrap;
self.label.font = [UIFont fontWithName:@"Optima-Regular" size:20];
self.label.autoDetectLinks = YES;
self.label.dataTypes = NSTextCheckingAllSystemTypes;
self.label.dataDetectorTypes = NSTextCheckingAllSystemTypes;

// When we enable defering the link detection is offloaded to a separate thread. This allows
// the label to display its text immediately and redraw itself once the links have been
Expand Down
50 changes: 30 additions & 20 deletions src/attributedlabel/src/NIAttributedLabel.h
Expand Up @@ -27,25 +27,14 @@
/**
* A UILabel that utilizes NSAttributedString to format its text.
*
* A note on using lineBreakMode with NIAttributedLabel:
* CoreText's line break mode functionality does not work the same way as UILabel.
* Differences between UILabel and NIAttributedLabel:
*
* UILabel: when you use truncation modes with multiline labels, the text will be treated as
* one continuous string. The documentation for each UILineBreakMode value applies correctly to
* UILabels.
*
* NIAttributedLabel: when you use truncation modes with multiline labels, the modes behave
* differently:
*
* - UILineBreakModeWordWrap, UILineBreakModeCharacterWrap: wraps the text over multiple lines with
* no truncation.
* - UILineBreakModeHeadTruncation, UILineBreakModeTailTruncation, UILineBreakModeMiddleTruncation:
* will only break the text onto a new line when a \n character is encountered. Each line is
* truncated with the line break mode.
*
* In short: if you want to use truncation with a multiline attributed label then you need to
* manually wrap the lines by using \n characters. If you don't need truncation then you can use
* the word wrap and character wrap modes to have the text automatically wrap.
* - UILineBreakModeHeadTruncation, UILineBreakModeTailTruncation, and
* UILineBreakModeMiddleTruncation only apply to single lines and will not wrap the label
* regardless of the numberOfLines property. To wrap liines with any of these line break modes
* you must explicitly add \n characters to the string.
* - When you assign an NSString to the text property the attributed label will create an
* attributed string that inherits all of the label's current styles.
*
* @ingroup NimbusAttributedLabel
*/
Expand All @@ -54,8 +43,9 @@
@property (nonatomic, copy) NSAttributedString* attributedString;

@property (nonatomic, assign) BOOL autoDetectLinks; // Default: NO
@property (nonatomic, assign) NSTextCheckingType dataDetectorTypes; // Default: NSTextCheckingTypeLink
@property (nonatomic, assign) BOOL deferLinkDetection; // Default: NO
@property (nonatomic, assign) NSTextCheckingType dataTypes; // Default: NSTextCheckingTypeLink

- (void)addLink:(NSURL *)urlLink range:(NSRange)range;
- (void)removeAllExplicitLinks; // Removes all links that were added by addLink:range:. Does not remove autodetected links.

Expand Down Expand Up @@ -94,6 +84,8 @@

@end

/** @name Accessing the Text Attributes */

/**
* The attributed string that will be displayed.
*
Expand All @@ -107,6 +99,8 @@
* @fn NIAttributedLabel::attributedString
*/

/** @name Accessing and Detecting Links */

/**
* Whether to automatically detect links in the string.
*
Expand Down Expand Up @@ -136,7 +130,15 @@
*/

/**
* Adds a link at a given range.
* The types of data that will be detected when autoDetectLinks is enabled.
*
* By default this is NSTextCheckingTypeLink.
*
* @fn NIAttributedLabel::dataDetectorTypes
*/

/**
* 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.
Expand All @@ -152,6 +154,8 @@
* @fn NIAttributedLabel::removeAllExplicitLinks
*/

/** @name Accessing Link Display Styles */

/**
* The color of detected links.
*
Expand Down Expand Up @@ -181,6 +185,8 @@
* @fn NIAttributedLabel::linksHaveUnderlines
*/

/** @name Modifying Rich Text Styles for All Text */

/**
* The underline style for the whole text.
*
Expand Down Expand Up @@ -233,6 +239,8 @@
* @fn NIAttributedLabel::textKern
*/

/** @name Modifying Rich Text Styles for Specific Ranges */

/**
* Sets the text color for a given range.
*
Expand Down Expand Up @@ -303,6 +311,8 @@
* @fn NIAttributedLabel::setTextKern:range:
*/

/** @name Accessing the Delegate */

/**
* The attributed label notifies the delegate of any user interactions.
*
Expand Down
6 changes: 3 additions & 3 deletions src/attributedlabel/src/NIAttributedLabel.m
Expand Up @@ -52,7 +52,7 @@ @implementation NIAttributedLabel
@synthesize touchedLink = _touchedLink;
@synthesize autoDetectLinks = _autoDetectLinks;
@synthesize deferLinkDetection = _deferLinkDetection;
@synthesize dataTypes = _dataTypes;
@synthesize dataDetectorTypes = _dataDetectorTypes;
@synthesize underlineStyle = _underlineStyle;
@synthesize underlineStyleModifier = _underlineStyleModifier;
@synthesize strokeWidth = _strokeWidth;
Expand All @@ -75,7 +75,7 @@ - (void)dealloc {
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)_configureDefaults {
self.linkColor = [UIColor blueColor];
self.dataTypes = NSTextCheckingTypeLink;
self.dataDetectorTypes = NSTextCheckingTypeLink;
self.highlightedLinkColor = [UIColor colorWithWhite:0.5f alpha:0.5f];
}

Expand Down Expand Up @@ -402,7 +402,7 @@ - (void)setLinksHaveUnderlines:(BOOL)linksHaveUnderlines {
///////////////////////////////////////////////////////////////////////////////////////////////////
- (NSArray *)_matchesFromAttributedString:(NSString *)string {
NSError* error = nil;
NSDataDetector* linkDetector = [NSDataDetector dataDetectorWithTypes:self.dataTypes
NSDataDetector* linkDetector = [NSDataDetector dataDetectorWithTypes:self.dataDetectorTypes
error:&error];
NSRange range = NSMakeRange(0, string.length);

Expand Down

0 comments on commit 6e5c685

Please sign in to comment.