diff options
author | gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2014-08-26 20:00:09 +0000 |
---|---|---|
committer | gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2014-08-26 20:00:09 +0000 |
commit | beb4c1c4a1ccae659f777f004d866f1b372d518d (patch) | |
tree | fca35fbf19f39b691c14f53e4914e5bee3883870 /iPhone | |
parent | 9cb4be9a147d217254a82a8602182fa3bcc2264e (diff) |
Restore GTMFadeTruncatingLabel's ability to render text in any color other than
black.
DELTA=16 (14 added, 1 deleted, 1 changed)
DELTA_BY_EXTENSION=m=15
Diffstat (limited to 'iPhone')
-rwxr-xr-x | iPhone/GTMFadeTruncatingLabel.m | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/iPhone/GTMFadeTruncatingLabel.m b/iPhone/GTMFadeTruncatingLabel.m index 7cdf0cb..3be7688 100755 --- a/iPhone/GTMFadeTruncatingLabel.m +++ b/iPhone/GTMFadeTruncatingLabel.m @@ -64,12 +64,12 @@ } if (self.shadowColor) { - CGContextSetFillColorWithColor(context, self.shadowColor.CGColor); CGRect shadowRect = CGRectOffset(requestedRect, self.shadowOffset.width, self.shadowOffset.height); #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0 // |drawInRect:withFont:lineBreakMode:alignment:| is deprecated in iOS 7, // replaced by |drawInRect:withAttributes:| + CGContextSetFillColorWithColor(context, self.shadowColor.CGColor); [self.text drawInRect:shadowRect withFont:self.font lineBreakMode:self.lineBreakMode @@ -82,16 +82,28 @@ NSDictionary* attributes = @{ NSFontAttributeName:self.font, NSParagraphStyleAttributeName:textStyle, + NSForegroundColorAttributeName:self.shadowColor }; [self.text drawInRect:shadowRect withAttributes:attributes]; #endif } - CGContextSetFillColorWithColor(context, self.textColor.CGColor); + // We check for nilness of shadowColor above, but there's no need to do so + // for textColor here because UILabel's textColor property cannot be nil. + // The UILabel docs say the default textColor is black and experimentation + // shows that calling -textColor will return the cached [UIColor blackColor] + // when called on a freshly alloc/init-ed UILabel, or a UILabel whose + // textColor has been set to nil. + // + // @see https://developer.apple.com/Library/ios/documentation/UIKit/Reference/UILabel_Class/Reference/UILabel.html#//apple_ref/occ/instp/UILabel/textColor + // (NOTE(bgoodwin): interesting side-note. These docs also say setting + // textColor to nil will result in an exception. In my testing, that did not + // happen.) #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0 // |drawInRect:withFont:lineBreakMode:alignment:| is deprecated in iOS 7, // replaced by |drawInRect:withAttributes:| + CGContextSetFillColorWithColor(context, self.textColor.CGColor); [self.text drawInRect:requestedRect withFont:self.font lineBreakMode:self.lineBreakMode @@ -104,6 +116,7 @@ NSDictionary* attributes = @{ NSFontAttributeName:self.font, NSParagraphStyleAttributeName:textStyle, + NSForegroundColorAttributeName:self.textColor }; [self.text drawInRect:requestedRect withAttributes:attributes]; |