pragma mark++++根据文字的大小计算size++++
- (CGSize)sizeWithText:(NSString *)text font:(UIFont *)font maxSize:(CGSize)maxSize
{
NSDictionary *attrs = @{NSFontAttributeName : font};// NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine
return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin |NSStringDrawingTruncatesLastVisibleLine attributes:attrs context:nil].size;
}
pragma mark++++ 带换行符垂直布局 根据文字的大小计算size++++
-
(CGSize)sizeWithText2:(NSString *)text font:(UIFont *)font maxSize:(CGSize)maxSize
{
CGSize size ;CGFloat h =0;
NSArraystrArr=[text componentsSeparatedByString:@"\n"];
for (NSStringstr in strArr)
{
CGSize size1 = [self sizeWithText:str font:font maxSize:maxSize];
h= h+size1.height;
}
size = CGSizeMake(maxSize.width, h);
return size;
}
网友评论