From 9cb4be9a147d217254a82a8602182fa3bcc2264e Mon Sep 17 00:00:00 2001 From: "gtm.daemon" Date: Wed, 20 Aug 2014 18:00:16 +0000 Subject: Fix compilation against iOS 7 deployment target. DELTA=35 (34 added, 0 deleted, 1 changed) DELTA_BY_EXTENSION=m=35 --- iPhone/GTMFadeTruncatingLabel.m | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'iPhone') diff --git a/iPhone/GTMFadeTruncatingLabel.m b/iPhone/GTMFadeTruncatingLabel.m index 0a5d0bb..7cdf0cb 100755 --- a/iPhone/GTMFadeTruncatingLabel.m +++ b/iPhone/GTMFadeTruncatingLabel.m @@ -49,7 +49,12 @@ CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSaveGState(context); +#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0 + // |sizeWithFont:| is deprecated in iOS 7, replaced by |sizeWithAttributes:| CGSize size = [self.text sizeWithFont:self.font]; +#else + CGSize size = [self.text sizeWithAttributes:@{NSFontAttributeName:self.font}]; +#endif if (size.width > requestedRect.size.width) { UIImage* image = [[self class] getLinearGradient:requestedRect @@ -62,18 +67,47 @@ 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:| [self.text drawInRect:shadowRect withFont:self.font lineBreakMode:self.lineBreakMode alignment:self.textAlignment]; +#else + NSMutableParagraphStyle* textStyle = + [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease]; + textStyle.lineBreakMode = self.lineBreakMode; + textStyle.alignment = self.textAlignment; + NSDictionary* attributes = @{ + NSFontAttributeName:self.font, + NSParagraphStyleAttributeName:textStyle, + }; + [self.text drawInRect:shadowRect + withAttributes:attributes]; +#endif } CGContextSetFillColorWithColor(context, self.textColor.CGColor); +#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0 + // |drawInRect:withFont:lineBreakMode:alignment:| is deprecated in iOS 7, + // replaced by |drawInRect:withAttributes:| [self.text drawInRect:requestedRect withFont:self.font lineBreakMode:self.lineBreakMode alignment:self.textAlignment]; - +#else + NSMutableParagraphStyle* textStyle = + [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease]; + textStyle.lineBreakMode = self.lineBreakMode; + textStyle.alignment = self.textAlignment; + NSDictionary* attributes = @{ + NSFontAttributeName:self.font, + NSParagraphStyleAttributeName:textStyle, + }; + [self.text drawInRect:requestedRect + withAttributes:attributes]; +#endif CGContextRestoreGState(context); } -- cgit v1.2.3