1.设置随机颜色
cell.backgroundColor = [UIColor colorWithRed:arc4random()%255/255.0 green:arc4random()%255/255.0 blue:arc4random()%255/255.0 alpha:1];
2.通过给定"字符内容" "字体大小" "View的宽度" 计算高度
#pragma mark- 通过内容动态计算高度
-(CGFloat)textHeight:(NSString *)string andFont:(UIFont *)fontSize andWith:(CGFloat)numSize{
NSString * text = string;
UIFont * font = fontSize;
CGSize size = CGSizeMake(numSize, MAXFLOAT);
NSDictionary * dic = [NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName, nil];
size = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin |NSStringDrawingUsesFontLeading attributes:dic context:nil].size;
return size.height;
}
网友评论