MRC改ARC,顺便优化一些系统废弃的API

drawInRect方法

//iOS8废弃
- (CGSize)drawInRect:(CGRect)rect withFont:(UIFont *)font lineBreakMode:(NSLineBreakMode)lineBreakMode alignment:(NSTextAlignment)alignment
  //iOS7以后
NSMutableParagraphStyle *titleStyle = [[[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy]autorelease];
titleStyle.lineBreakMode = NSLineBreakByTruncatingTail;
titleStyle.alignment = NSTextAlignmentLeft;
NSDictionary *titleAttribute = @{
                                NSFontAttributeName:titleFont,
                                NSParagraphStyleAttributeName:titleStyle
                                };
[_title drawInRect:r withAttributes:titleAttribute];
CGSize s = [_title sizeWithAttributes:titleAttribute];

sizeWithFont方法

//iOS7以后
NSDictionary *attribute = @{NSFontAttributeName:withFont};
    return [text boundingRectWithSize:CGSizeMake(width, FLT_MAX) options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;
//iOS8废弃
[text sizeWithFont:withFont
 constrainedToSize:CGSizeMake(width, FLT_MAX) 
     lineBreakMode:lineBreakMode]

已经弃用,欢迎移步我的小专栏:
https://xiaozhuanlan.com/dahuihuiiOS

你可能感兴趣的:(MRC改ARC,顺便优化一些系统废弃的API)