自定义cell中UILabel文字换行显示

来源:互联网 发布:用网络命令查看dns 编辑:程序博客网 时间:2024/06/06 00:15

自定义cell中UILabel文字换行显示

1.设置UILabel属性 numberOfLines = 0
@property(nonatomic) NSInteger numberOfLines 这个属性是显示UILabel显示最大行数,但是如果想对行数不对限制,就设其为0.文档中:To remove any maximum limit, and use as many lines as needed, set the value of this property to 0.

2.设置UILabel中字体显示的的最大宽度
- (CGSize)sizeWithText : (NSString *)text font : (UIFont *)font maxW : (CGFloat)maxW
{
NSMutableDictionary *atts = [NSMutableDictionary dictionary];
atts[NSFontAttributeName] = font;
CGSize maxSize = CGSizeMake(maxW, MAXFLOAT);
return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:atts context:nil].size;
}

这样UILabel中得文字就可以分行显示了。

0 0