Skip to content

Commit

Permalink
Remove deprecations & outdated compatibility code
Browse files Browse the repository at this point in the history
  • Loading branch information
segiddins committed May 10, 2016
1 parent d04ba7c commit 11d45ef
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 162 deletions.
9 changes: 2 additions & 7 deletions Example/DetailViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
#import "DetailViewController.h"
#import "TTTAttributedLabel.h"

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

static CGFloat const kEspressoDescriptionTextFontSize = 17.0f;

static inline NSRegularExpression * NameRegularExpression() {
Expand Down Expand Up @@ -91,8 +88,8 @@ - (void)viewDidLoad {
UIFont *f = [UIFont systemFontOfSize:kEspressoDescriptionTextFontSize];
self.attributedLabel.font = f;
self.attributedLabel.textColor = [UIColor darkGrayColor];
self.attributedLabel.lineBreakMode = UILineBreakModeWordWrap;
self.attributedLabel.leading = -100;
self.attributedLabel.lineBreakMode = NSLineBreakByWordWrapping;
self.attributedLabel.lineSpacing = -100;
self.attributedLabel.maximumLineHeight = f.lineHeight;
self.attributedLabel.minimumLineHeight = f.lineHeight;
self.attributedLabel.numberOfLines = 0;
Expand Down Expand Up @@ -162,5 +159,3 @@ - (void)actionSheet:(UIActionSheet *)actionSheet
}

@end

#pragma clang diagnostic pop
19 changes: 0 additions & 19 deletions Example/TTTAttributedLabelTests/TTTAttributedLabelTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -1046,23 +1046,4 @@ - (void)testLinkAccessibility {
timeStyle:NSDateFormatterLongStyle]);
}

#pragma mark - Deprecated Methods

- (void)testLeading {
// Deprecated
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[label setLeading:1.f];
#pragma clang diagnostic pop
expect(label.lineSpacing).to.equal(1.f);
}

- (void)testDataDetectorTypes {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
label.dataDetectorTypes = NSTextCheckingTypeLink;
expect(label.dataDetectorTypes).will.equal(NSTextCheckingTypeLink);
#pragma clang diagnostic pop
}

@end
20 changes: 0 additions & 20 deletions TTTAttributedLabel/TTTAttributedLabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@ IB_DESIGNABLE
/// @name Detecting, Accessing, & Styling Links
///--------------------------------------------

/**
@deprecated Use `enabledTextCheckingTypes` property instead.
*/
@property (nonatomic, assign) NSTextCheckingTypes dataDetectorTypes DEPRECATED_ATTRIBUTE;

/**
A bitmask of `NSTextCheckingType` which are used to automatically detect links in the label text.
Expand Down Expand Up @@ -209,11 +204,6 @@ IB_DESIGNABLE
*/
@property (nonatomic, assign) IBInspectable CGFloat firstLineIndent;

/**
@deprecated Use `lineSpacing` instead.
*/
@property (nonatomic, assign) IBInspectable 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.
*/
Expand Down Expand Up @@ -258,16 +248,6 @@ IB_DESIGNABLE
/// @name Accessing Truncation Token Appearance
///--------------------------------------------

/**
@deprecated Use `attributedTruncationToken` instead.
*/
@property (nonatomic, strong) NSString *truncationTokenString DEPRECATED_ATTRIBUTE;

/**
@deprecated Use `attributedTruncationToken` instead.
*/
@property (nonatomic, strong) NSDictionary *truncationTokenStringAttributes DEPRECATED_ATTRIBUTE;

/**
The attributed string to apply to the truncation token at the end of a truncated line. Overrides `truncationTokenStringAttributes` and `truncationTokenString`. If unspecified, attributes will fallback to `truncationTokenStringAttributes` and `truncationTokenString`.
*/
Expand Down
127 changes: 11 additions & 116 deletions TTTAttributedLabel/TTTAttributedLabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
NSString * const kTTTBackgroundLineWidthAttributeName = @"TTTBackgroundLineWidth";
NSString * const kTTTBackgroundCornerRadiusAttributeName = @"TTTBackgroundCornerRadius";

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 60000
const NSTextAlignment TTTTextAlignmentLeft = NSTextAlignmentLeft;
const NSTextAlignment TTTTextAlignmentCenter = NSTextAlignmentCenter;
const NSTextAlignment TTTTextAlignmentRight = NSTextAlignmentRight;
Expand All @@ -53,27 +52,9 @@

typedef NSTextAlignment TTTTextAlignment;
typedef NSLineBreakMode TTTLineBreakMode;
#else
const UITextAlignment TTTTextAlignmentLeft = NSTextAlignmentLeft;
const UITextAlignment TTTTextAlignmentCenter = NSTextAlignmentCenter;
const UITextAlignment TTTTextAlignmentRight = NSTextAlignmentRight;
const UITextAlignment TTTTextAlignmentJustified = NSTextAlignmentJustified;
const UITextAlignment TTTTextAlignmentNatural = NSTextAlignmentNatural;

const UITextAlignment TTTLineBreakByWordWrapping = NSLineBreakByWordWrapping;
const UITextAlignment TTTLineBreakByCharWrapping = NSLineBreakByCharWrapping;
const UITextAlignment TTTLineBreakByClipping = NSLineBreakByClipping;
const UITextAlignment TTTLineBreakByTruncatingHead = NSLineBreakByTruncatingHead;
const UITextAlignment TTTLineBreakByTruncatingMiddle = NSLineBreakByTruncatingMiddle;
const UITextAlignment TTTLineBreakByTruncatingTail = NSLineBreakByTruncatingTail;

typedef UITextAlignment TTTTextAlignment;
typedef UILineBreakMode TTTLineBreakMode;
#endif


static inline CTTextAlignment CTTextAlignmentFromTTTTextAlignment(TTTTextAlignment alignment) {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 60000
switch (alignment) {
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 90000
case NSTextAlignmentLeft: return kCTTextAlignmentLeft;
Expand All @@ -87,18 +68,9 @@ static inline CTTextAlignment CTTextAlignmentFromTTTTextAlignment(TTTTextAlignme
default: return kCTNaturalTextAlignment;
#endif
}
#else
switch (alignment) {
case UITextAlignmentLeft: return kCTLeftTextAlignment;
case UITextAlignmentCenter: return kCTCenterTextAlignment;
case UITextAlignmentRight: return kCTRightTextAlignment;
default: return kCTNaturalTextAlignment;
}
#endif
}

static inline CTLineBreakMode CTLineBreakModeFromTTTLineBreakMode(TTTLineBreakMode lineBreakMode) {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 60000
switch (lineBreakMode) {
case NSLineBreakByWordWrapping: return kCTLineBreakByWordWrapping;
case NSLineBreakByCharWrapping: return kCTLineBreakByCharWrapping;
Expand All @@ -108,28 +80,8 @@ static inline CTLineBreakMode CTLineBreakModeFromTTTLineBreakMode(TTTLineBreakMo
case NSLineBreakByTruncatingMiddle: return kCTLineBreakByTruncatingMiddle;
default: return 0;
}
#else
return CTLineBreakModeFromUILineBreakMode(lineBreakMode);
#endif
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED < 60000
static inline CTLineBreakMode CTLineBreakModeFromUILineBreakMode(UILineBreakMode lineBreakMode) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
switch (lineBreakMode) {
case UILineBreakModeWordWrap: return kCTLineBreakByWordWrapping;
case UILineBreakModeCharacterWrap: return kCTLineBreakByCharWrapping;
case UILineBreakModeClip: return kCTLineBreakByClipping;
case UILineBreakModeHeadTruncation: return kCTLineBreakByTruncatingHead;
case UILineBreakModeTailTruncation: return kCTLineBreakByTruncatingTail;
case UILineBreakModeMiddleTruncation: return kCTLineBreakByTruncatingMiddle;
default: return 0;
}
#pragma clang diagnostic pop
}
#endif

static inline CGFLOAT_TYPE CGFloat_ceil(CGFLOAT_TYPE cgfloat) {
#if CGFLOAT_IS_DOUBLE
return ceil(cgfloat);
Expand Down Expand Up @@ -316,8 +268,6 @@ static inline CGSize CTFramesetterSuggestFrameSizeForAttributedStringWithConstra
return CGSizeMake(CGFloat_ceil(suggestedSize.width), CGFloat_ceil(suggestedSize.height));
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000

@interface TTTAccessibilityElement : UIAccessibilityElement
@property (nonatomic, weak) UIView *superview;
@property (nonatomic, assign) CGRect boundingRect;
Expand All @@ -331,8 +281,6 @@ - (CGRect)accessibilityFrame {

@end

#endif

@interface TTTAttributedLabel ()
@property (readwrite, nonatomic, copy) NSAttributedString *inactiveAttributedText;
@property (readwrite, nonatomic, copy) NSAttributedString *renderedAttributedText;
Expand All @@ -354,8 +302,6 @@ @implementation TTTAttributedLabel {
@dynamic text;
@synthesize attributedText = _attributedText;

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000

#ifndef kCFCoreFoundationVersionNumber_iOS_7_0
#define kCFCoreFoundationVersionNumber_iOS_7_0 847.2
#endif
Expand Down Expand Up @@ -384,7 +330,6 @@ + (void)load {
}
});
}
#endif

- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
Expand Down Expand Up @@ -484,11 +429,9 @@ - (void)setAttributedText:(NSAttributedString *)text {
[self setNeedsFramesetter];
[self setNeedsDisplay];

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 60000
if ([self respondsToSelector:@selector(invalidateIntrinsicContentSize)]) {
[self invalidateIntrinsicContentSize];
}
#endif

[super setText:[self.attributedText string]];
}
Expand Down Expand Up @@ -563,24 +506,8 @@ - (void)setHighlightFramesetter:(CTFramesetterRef)highlightFramesetter {
_highlightFramesetter = highlightFramesetter;
}

- (CGFloat)leading {
return self.lineSpacing;
}

- (void)setLeading:(CGFloat)leading {
self.lineSpacing = leading;
}

#pragma mark -

- (NSTextCheckingTypes)dataDetectorTypes {
return self.enabledTextCheckingTypes;
}

- (void)setDataDetectorTypes:(NSTextCheckingTypes)dataDetectorTypes {
self.enabledTextCheckingTypes = dataDetectorTypes;
}

- (void)setEnabledTextCheckingTypes:(NSTextCheckingTypes)enabledTextCheckingTypes {
if (self.enabledTextCheckingTypes == enabledTextCheckingTypes) {
return;
Expand Down Expand Up @@ -838,7 +765,6 @@ - (CFIndex)characterIndexAtPoint:(CGPoint)p {
return idx;
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000
- (CGRect)boundingRectForCharacterRange:(NSRange)range {
NSMutableAttributedString *mutableAttributedString = [self.attributedText mutableCopy];

Expand All @@ -855,7 +781,6 @@ - (CGRect)boundingRectForCharacterRange:(NSRange)range {

return [layoutManager boundingRectForGlyphRange:glyphRange inTextContainer:textContainer];
}
#endif

- (void)drawFramesetter:(CTFramesetterRef)framesetter
attributedString:(NSAttributedString *)attributedString
Expand Down Expand Up @@ -917,24 +842,15 @@ - (void)drawFramesetter:(CTFramesetterRef)framesetter
break;
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSAttributedString *attributedTruncationString = self.attributedTruncationToken;
if (!attributedTruncationString) {
NSString *truncationTokenString = self.truncationTokenString;
if (!truncationTokenString) {
truncationTokenString = @"\u2026"; // Unicode Character 'HORIZONTAL ELLIPSIS' (U+2026)
}
NSString *truncationTokenString = @"\u2026"; // Unicode Character 'HORIZONTAL ELLIPSIS' (U+2026)

NSDictionary *truncationTokenStringAttributes = self.truncationTokenStringAttributes;
if (!truncationTokenStringAttributes) {
truncationTokenStringAttributes = [attributedString attributesAtIndex:(NSUInteger)truncationAttributePosition effectiveRange:NULL];
}
NSDictionary *truncationTokenStringAttributes = truncationTokenStringAttributes = [attributedString attributesAtIndex:(NSUInteger)truncationAttributePosition effectiveRange:NULL];

attributedTruncationString = [[NSAttributedString alloc] initWithString:truncationTokenString attributes:truncationTokenStringAttributes];
}
CTLineRef truncationToken = CTLineCreateWithAttributedString((__bridge CFAttributedStringRef)attributedTruncationString);
#pragma clang diagnostic pop

// Append truncationToken to the string
// because if string isn't too long, CT won't add the truncationToken on its own.
Expand Down Expand Up @@ -1161,11 +1077,7 @@ - (void)setText:(id)text {

self.linkModels = [NSArray array];
if (text && self.attributedText && self.enabledTextCheckingTypes) {
#if __IPHONE_OS_VERSION_MIN_REQUIRED < 50000
__unsafe_unretained __typeof(self)weakSelf = self;
#else
__weak __typeof(self)weakSelf = self;
#endif
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
__strong __typeof(weakSelf)strongSelf = weakSelf;

Expand All @@ -1183,16 +1095,12 @@ - (void)setText:(id)text {
});
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000
if (&NSLinkAttributeName) {
[self.attributedText enumerateAttribute:NSLinkAttributeName inRange:NSMakeRange(0, self.attributedText.length) options:0 usingBlock:^(id value, __unused NSRange range, __unused BOOL *stop) {
if (value) {
NSURL *URL = [value isKindOfClass:[NSString class]] ? [NSURL URLWithString:value] : value;
[self addLinkToURL:URL withRange:range];
}
}];
}
#endif
[self.attributedText enumerateAttribute:NSLinkAttributeName inRange:NSMakeRange(0, self.attributedText.length) options:0 usingBlock:^(id value, __unused NSRange range, __unused BOOL *stop) {
if (value) {
NSURL *URL = [value isKindOfClass:[NSString class]] ? [NSURL URLWithString:value] : value;
[self addLinkToURL:URL withRange:range];
}
}];
}

- (void)setText:(id)text
Expand Down Expand Up @@ -1334,11 +1242,9 @@ - (void)drawTextInRect:(CGRect)rect {
[self setNeedsFramesetter];
[self setNeedsDisplay];

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 60000
if ([self respondsToSelector:@selector(invalidateIntrinsicContentSize)]) {
[self invalidateIntrinsicContentSize];
}
#endif

// Use infinite width to find the max width, which will be compared to availableWidth if needed.
CGSize maxSize = (self.numberOfLines > 1) ? CGSizeMake(TTTFLOAT_MAX, TTTFLOAT_MAX) : CGSizeZero;
Expand Down Expand Up @@ -1412,8 +1318,6 @@ - (void)drawTextInRect:(CGRect)rect {

#pragma mark - UIAccessibilityElement

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000

- (BOOL)isAccessibilityElement {
return NO;
}
Expand Down Expand Up @@ -1477,7 +1381,6 @@ - (NSArray *)accessibilityElements {

return _accessibilityElements;
}
#endif

#pragma mark - UIView

Expand Down Expand Up @@ -1506,7 +1409,6 @@ - (CGSize)intrinsicContentSize {
return [self sizeThatFits:[super intrinsicContentSize]];
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000
- (void)tintColorDidChange {
if (!self.inactiveLinkAttributes || [self.inactiveLinkAttributes count] == 0) {
return;
Expand Down Expand Up @@ -1536,7 +1438,6 @@ - (void)tintColorDidChange {

[self setNeedsDisplay];
}
#endif

- (UIView *)hitTest:(CGPoint)point
withEvent:(UIEvent *)event
Expand Down Expand Up @@ -1766,10 +1667,7 @@ - (void)encodeWithCoder:(NSCoder *)coder {
[coder encodeUIEdgeInsets:self.textInsets forKey:NSStringFromSelector(@selector(textInsets))];
[coder encodeInteger:self.verticalAlignment forKey:NSStringFromSelector(@selector(verticalAlignment))];

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[coder encodeObject:self.truncationTokenString forKey:NSStringFromSelector(@selector(truncationTokenString))];
#pragma clang diagnostic pop
[coder encodeObject:self.attributedTruncationToken forKey:NSStringFromSelector(@selector(attributedTruncationToken))];

[coder encodeObject:NSStringFromUIEdgeInsets(self.linkBackgroundEdgeInset) forKey:NSStringFromSelector(@selector(linkBackgroundEdgeInset))];
[coder encodeObject:self.attributedText forKey:NSStringFromSelector(@selector(attributedText))];
Expand Down Expand Up @@ -1859,12 +1757,9 @@ - (id)initWithCoder:(NSCoder *)coder {
self.verticalAlignment = [coder decodeIntegerForKey:NSStringFromSelector(@selector(verticalAlignment))];
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
if ([coder containsValueForKey:NSStringFromSelector(@selector(truncationTokenString))]) {
self.truncationTokenString = [coder decodeObjectForKey:NSStringFromSelector(@selector(truncationTokenString))];
if ([coder containsValueForKey:NSStringFromSelector(@selector(attributedTruncationToken))]) {
self.attributedTruncationToken = [coder decodeObjectForKey:NSStringFromSelector(@selector(attributedTruncationToken))];
}
#pragma clang diagnostic pop

if ([coder containsValueForKey:NSStringFromSelector(@selector(linkBackgroundEdgeInset))]) {
self.linkBackgroundEdgeInset = UIEdgeInsetsFromString([coder decodeObjectForKey:NSStringFromSelector(@selector(linkBackgroundEdgeInset))]);
Expand Down

0 comments on commit 11d45ef

Please sign in to comment.