Skip to content

Commit

Permalink
Merge branch 'master' into master-milq
Browse files Browse the repository at this point in the history
* master: (61 commits)
  Add missing __bridge to casts in order to avoid errors building for iOS 6
  Adding Communication section to README
  Minor README copy-editing
  Add accessibility documentation to README
  Replace deprecated `leading` with `lineSpacing` in README.
  Bumping version to 1.10.0
  Replacing __LP64__ macros with more semantic  CGFLOAT_IS_DOUBLE
  [Issue #380] Taking minimumScaleFactor into account for automatic resizing of text
  [Issue #376] Fixing alignment and trunctionation issue on last line of text
  [Issue #385] Deprecating leading property, in favor of lineSpacing property
  [Issue #383] Reorganizing and refactoring boundingRectForCharacterRange:
  [Issue #383] Adding support for UIAccessibilityElement
  fix hitTest:WithEvent:
  Fixing precision warning with double to CGFloat conversion
  Changing return type of initWithFrame to instancetype
  [Issue #359] Implementing init, to allow for use with non-designated initializer with auto layout
  [Issue #372] Punching up documentation for active and inactive links
  [Issue #372] Minor code reformatting
  [FIX] lineHeightMultiple is ignored.
  [Issue #371] Opt out of inactive link styling when inactiveLinkAttributes is `nil` or empty.
  ...
  • Loading branch information
runmad committed Jun 4, 2014
2 parents 3380be0 + 6e2d043 commit 2a4e2a0
Show file tree
Hide file tree
Showing 7 changed files with 483 additions and 217 deletions.
37 changes: 27 additions & 10 deletions Example/AttributedTableViewCell.m
Expand Up @@ -24,11 +24,7 @@
#import "AttributedTableViewCell.h"
#import "TTTAttributedLabel.h"

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"

static CGFloat const kEspressoDescriptionTextFontSize = 17;
static CGFloat const kAttributedTableViewCellVerticalMargin = 20.0f;

static inline NSRegularExpression * NameRegularExpression() {
static NSRegularExpression *_nameRegularExpression = nil;
Expand Down Expand Up @@ -80,7 +76,7 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
self.summaryLabel.activeLinkAttributes = mutableActiveLinkAttributes;

self.summaryLabel.highlightedTextColor = [UIColor whiteColor];
self.summaryLabel.shadowColor = [UIColor colorWithWhite:0.87 alpha:1.0];
self.summaryLabel.shadowColor = [UIColor colorWithWhite:0.87f alpha:1.0f];
self.summaryLabel.shadowOffset = CGSizeMake(0.0f, 1.0f);
self.summaryLabel.highlightedShadowColor = [UIColor colorWithWhite:0.0f alpha:0.25f];
self.summaryLabel.highlightedShadowOffset = CGSizeMake(0.0f, -1.0f);
Expand All @@ -89,19 +85,24 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus

[self.contentView addSubview:self.summaryLabel];

self.isAccessibilityElement = NO;

return self;
}


- (void)setSummaryText:(NSString *)text {
_summaryText = [text copy];
}

- (void)drawRect:(CGRect)rect {
[super drawRect:rect];

[self.summaryLabel setText:self.summaryText afterInheritingLabelAttributesAndConfiguringWithBlock:^NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString) {
NSRange stringRange = NSMakeRange(0, [mutableAttributedString length]);

NSRegularExpression *regexp = NameRegularExpression();
NSRange nameRange = [regexp rangeOfFirstMatchInString:[mutableAttributedString string] options:0 range:stringRange];
UIFont *boldSystemFont = [UIFont boldSystemFontOfSize:kEspressoDescriptionTextFontSize];
UIFont *boldSystemFont = [UIFont boldSystemFontOfSize:kEspressoDescriptionTextFontSize];
CTFontRef boldFont = CTFontCreateWithName((__bridge CFStringRef)boldSystemFont.fontName, boldSystemFont.pointSize, NULL);
if (boldFont) {
[mutableAttributedString removeAttribute:(__bridge NSString *)kCTFontAttributeName range:nameRange];
Expand All @@ -124,14 +125,16 @@ - (void)setSummaryText:(NSString *)text {
[mutableAttributedString addAttribute:(NSString *)kCTForegroundColorAttributeName value:(__bridge id)[[UIColor grayColor] CGColor] range:result.range];
}
}];

return mutableAttributedString;
}];

NSRegularExpression *regexp = NameRegularExpression();
NSRange linkRange = [regexp rangeOfFirstMatchInString:self.summaryText options:0 range:NSMakeRange(0, [self.summaryText length])];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://en.wikipedia.org/wiki/%@", [self.summaryText substringWithRange:linkRange]]];
[self.summaryLabel addLinkToURL:url withRange:linkRange];

[self.summaryLabel setNeedsDisplay];
}

+ (CGFloat)heightForCellWithText:(NSString *)text {
Expand All @@ -156,8 +159,22 @@ - (void)layoutSubviews {
self.detailTextLabel.hidden = YES;

self.summaryLabel.frame = CGRectOffset(CGRectInset(self.bounds, 20.0f, 5.0f), -10.0f, 0.0f);

[self setNeedsDisplay];
}

@end
#pragma mark - UIAccessibilityContainer

- (NSInteger)accessibilityElementCount {
return 1;
}

- (id)accessibilityElementAtIndex:(__unused NSInteger)index {
return self.summaryLabel;
}

- (NSInteger)indexOfAccessibilityElement:(__unused id)element {
return 0;
}

#pragma clang diagnostic pop
@end
6 changes: 5 additions & 1 deletion Example/DetailViewController.m
Expand Up @@ -88,9 +88,13 @@ - (void)viewDidLoad {
self.title = NSLocalizedString(@"Espresso", nil);

self.attributedLabel.delegate = self;
self.attributedLabel.font = [UIFont systemFontOfSize:kEspressoDescriptionTextFontSize];
UIFont *f = [UIFont systemFontOfSize:kEspressoDescriptionTextFontSize];
self.attributedLabel.font = f;
self.attributedLabel.textColor = [UIColor darkGrayColor];
self.attributedLabel.lineBreakMode = UILineBreakModeWordWrap;
self.attributedLabel.leading = -100;
self.attributedLabel.maximumLineHeight = f.lineHeight;
self.attributedLabel.minimumLineHeight = f.lineHeight;
self.attributedLabel.numberOfLines = 0;
self.attributedLabel.linkAttributes = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:(NSString *)kCTUnderlineStyleAttributeName];

Expand Down
6 changes: 4 additions & 2 deletions Example/Espressos.xcodeproj/project.pbxproj
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
F82DFABB16B837810095ECA8 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F82DFABA16B837810095ECA8 /* Default-568h@2x.png */; };
F83BDEAA18A5C2DF003893B2 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F83BDEA918A5C2DF003893B2 /* QuartzCore.framework */; };
F877A36113782AF10022A8AB /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F877A36013782AF10022A8AB /* UIKit.framework */; };
F877A36313782AF10022A8AB /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F877A36213782AF10022A8AB /* Foundation.framework */; };
F877A36513782AF10022A8AB /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F877A36413782AF10022A8AB /* CoreGraphics.framework */; };
Expand All @@ -23,6 +24,7 @@

/* Begin PBXFileReference section */
F82DFABA16B837810095ECA8 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = "<group>"; };
F83BDEA918A5C2DF003893B2 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
F877A35C13782AF10022A8AB /* Espressos.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Espressos.app; sourceTree = BUILT_PRODUCTS_DIR; };
F877A36013782AF10022A8AB /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
F877A36213782AF10022A8AB /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
Expand All @@ -49,6 +51,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
F83BDEAA18A5C2DF003893B2 /* QuartzCore.framework in Frameworks */,
F877A39513782FC10022A8AB /* CoreText.framework in Frameworks */,
F877A36113782AF10022A8AB /* UIKit.framework in Frameworks */,
F877A36313782AF10022A8AB /* Foundation.framework in Frameworks */,
Expand Down Expand Up @@ -81,6 +84,7 @@
F877A35F13782AF10022A8AB /* Frameworks */ = {
isa = PBXGroup;
children = (
F83BDEA918A5C2DF003893B2 /* QuartzCore.framework */,
F877A36013782AF10022A8AB /* UIKit.framework */,
F877A36213782AF10022A8AB /* Foundation.framework */,
F877A36413782AF10022A8AB /* CoreGraphics.framework */,
Expand Down Expand Up @@ -234,7 +238,6 @@
F877A37B13782AF10022A8AB /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
Expand Down Expand Up @@ -282,7 +285,6 @@
F877A37C13782AF10022A8AB /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
Expand Down
14 changes: 13 additions & 1 deletion README.md
Expand Up @@ -17,12 +17,24 @@ It also includes advanced paragraph style properties:
- `verticalAlignment`
- `textInsets`
- `firstLineIndent`
- `leading`
- `lineSpacing`
- `lineHeightMultiple`
- `shadowRadius`
- `highlightedShadowRadius` / `highlightedShadowOffset` / `highlightedShadowColor`
- `truncationTokenString`

### Accessibility

As of version 1.10.0, `TTTAttributedLabel` supports VoiceOver, through the `UIAccessibilityElement` protocol. Each link can be individually selected, with an `accessibilityLabel` equal to its string value, and a corresponding `accessibilityValue` for URL, phone number, and date links. Developers who wish to change this behavior or provide custom values should create a subclass and override `accessibilityElements`.

## Communication

- If you **need help**, use [Stack Overflow](http://stackoverflow.com/questions/tagged/tttattributedlabel). (Tag 'tttattributedlabel')
- If you'd like to **ask a general question**, use [Stack Overflow](http://stackoverflow.com/questions/tagged/tttattributedlabel).
- If you **found a bug**, open an issue.
- If you **have a feature request**, open an issue.
- If you **want to contribute**, submit a pull request.

## Installation

[CocoaPods](http://cocoapods.org) is the recommended method of installing TTTAttributedLabel. Simply add the following line to your `Podfile`:
Expand Down
7 changes: 4 additions & 3 deletions TTTAttributedLabel.podspec
@@ -1,17 +1,18 @@
Pod::Spec.new do |s|
s.name = 'TTTAttributedLabel'
s.version = '1.8.1'
s.version = '1.10.0'
s.authors = {'Mattt Thompson' => 'm@mattt.me'}
s.homepage = 'https://github.com/mattt/TTTAttributedLabel/'
s.social_media_url = 'https://twitter.com/mattt'
s.summary = 'A drop-in replacement for UILabel that supports attributes, data detectors, links, and more.'
s.source = {:git => 'https://github.com/mattt/TTTAttributedLabel.git', :tag => '1.8.1'}
s.source = {:git => 'https://github.com/mattt/TTTAttributedLabel.git', :tag => '1.10.0'}
s.license = 'MIT'

s.requires_arc = true

s.platform = :ios
s.ios.deployment_target = '4.3'

s.frameworks = 'CoreText', 'CoreGraphics'
s.frameworks = 'CoreText', 'CoreGraphics', 'QuartzCore'
s.source_files = 'TTTAttributedLabel'
end
34 changes: 28 additions & 6 deletions TTTAttributedLabel/TTTAttributedLabel.h
Expand Up @@ -26,11 +26,11 @@
/**
Vertical alignment for text in a label whose bounds are larger than its text bounds
*/
typedef enum {
typedef NS_ENUM(NSInteger, TTTAttributedLabelVerticalAlignment) {
TTTAttributedLabelVerticalAlignmentCenter = 0,
TTTAttributedLabelVerticalAlignmentTop = 1,
TTTAttributedLabelVerticalAlignmentBottom = 2,
} TTTAttributedLabelVerticalAlignment;
};

/**
Determines whether the text to which this attribute applies has a strikeout drawn through itself.
Expand Down Expand Up @@ -87,6 +87,8 @@ extern NSString * const kTTTBackgroundCornerRadiusAttributeName;
`TTTAttributedLabel`, like `UILabel`, conforms to `NSCoding`. However, if the build target is set to less than iOS 6.0, `linkAttributes` and `activeLinkAttributes` will not be encoded or decoded. This is due to an runtime exception thrown when attempting to copy non-object CoreText values in dictionaries.
@warning Any properties changed on the label after setting the text will not be reflected until a subsequent call to `setText:` or `setText:afterInheritingLabelAttributesAndConfiguringWithBlock:`. This is to say, order of operations matters in this case. For example, if the label text color is originally black when the text is set, changing the text color to red will have no effect on the display of the label until the text is set once again.
@bug Setting `attributedText` directly is not recommended, as it may cause a crash when attempting to access any links previously set. Instead, call `setText:`, passing an `NSAttributedString`.
*/
@interface TTTAttributedLabel : UILabel <TTTAttributedLabel, UIGestureRecognizerDelegate>

Expand Down Expand Up @@ -130,12 +132,12 @@ extern NSString * const kTTTBackgroundCornerRadiusAttributeName;
@property (nonatomic, strong) NSDictionary *linkAttributes;

/**
A dictionary containing the `NSAttributedString` attributes to be applied to links when they are in the active state. Supply `nil` or an empty dictionary to opt out of active link styling. The default active link style is red and underlined.
A dictionary containing the `NSAttributedString` attributes to be applied to links when they are in the active state. If `nil` or an empty `NSDictionary`, active links will not be styled. The default active link style is red and underlined.
*/
@property (nonatomic, strong) NSDictionary *activeLinkAttributes;

/**
A dictionary containing the `NSAttributedString` attributes to be applied to links when they are in the inactive state, which is triggered a change in `tintColor` in iOS 7. Supply `nil` or an empty dictionary to opt out of inactive link styling. The default inactive link style is gray and unadorned.
A dictionary containing the `NSAttributedString` attributes to be applied to links when they are in the inactive state, which is triggered a change in `tintColor` in iOS 7. If `nil` or an empty `NSDictionary`, inactive links will not be styled. The default inactive link style is gray and unadorned.
*/
@property (nonatomic, strong) NSDictionary *inactiveLinkAttributes;

Expand All @@ -161,6 +163,11 @@ extern NSString * const kTTTBackgroundCornerRadiusAttributeName;
*/
@property (nonatomic, strong) UIColor *highlightedShadowColor;

/**
The amount to kern the next character. Default is standard kerning. If this attribute is set to 0.0, no kerning is done at all.
*/
@property (nonatomic, assign) CGFloat kern;

///--------------------------------------------
/// @name Acccessing Paragraph Style Attributes
///--------------------------------------------
Expand All @@ -171,9 +178,24 @@ extern NSString * const kTTTBackgroundCornerRadiusAttributeName;
@property (nonatomic, assign) CGFloat firstLineIndent;

/**
The space in points added between lines within the paragraph. This value is always nonnegative and is 0.0 by default.
@deprecated Use `lineSpacing` instead.
*/
@property (nonatomic, assign) CGFloat leading DEPRECATED_ATTRIBUTE;

/**
The space in points added between lines within the paragraph. This value is always nonnegative and is 0.0 by default.
*/
@property (nonatomic, assign) CGFloat lineSpacing;

/**
The minimum line height within the paragraph. If the value is 0.0, the minimum line height is set to the line height of the `font`. 0.0 by default.
*/
@property (nonatomic, assign) CGFloat minimumLineHeight;

/**
The maximum line height within the paragraph. If the value is 0.0, the maximum line height is set to the line height of the `font`. 0.0 by default.
*/
@property (nonatomic, assign) CGFloat leading;
@property (nonatomic, assign) CGFloat maximumLineHeight;

/**
The line height multiple. This value is 1.0 by default.
Expand Down

0 comments on commit 2a4e2a0

Please sign in to comment.