/***
**自适应高度和宽度,其中参数widget是你要改变的label,size是定义label的长宽最大值,sizefont这个是字体的大小
***/
+(CGRect )xyAutoSizeOfWidget:(UILabel *)widget andSize:(CGSize)size andtextFont:(CGFloat )sizefont
{
widget.numberOfLines = 0;
CGRect rect = widget.frame;
NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:sizefont],NSFontAttributeName,nil];
CGSize actualsize =[widget.text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:tdic context:nil].size;
CGRect tmpRect = CGRectMake(rect.origin.x, rect.origin.y, actualsize.width, actualsize.height);
return tmpRect;
}
网友评论