iOS之label根据文字多少和尺寸确定其高度

 UILabel * label = [[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 195, 195)] autorelease];

        label.text = htmlStr;

        label.textColor = [UIColor colorWithRed:60/225.0 green:60/255.0 blue:60/255.0 alpha:1.0];

        [label setFont:[UIFont systemFontOfSize:15.0]];

        label.textAlignment = NSTextAlignmentLeft;

        label.numberOfLines = 0;

        CGSize size = [htmlStr sizeWithFont:label.font constrainedToSize:CGSizeMake(label.frame.size.width, MAXFLOAT) lineBreakMode:NSLineBreakByWordWrapping];

        label.frame = CGRectMake(0, 0, labelSize.width + 23, size.height+5);

posted on 2016-02-29 14:23  X了个code  阅读(429)  评论(0编辑  收藏  举报