drawInRect方法
//iOS8废弃
- (CGSize)drawInRect:(CGRect)rect withFont:(UIFont *)font lineBreakMode:(NSLineBreakMode)lineBreakMode alignment:(NSTextAlignment)alignment
</pre>
<pre> //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
网友评论