OC

Knowledge OS
登录 注册
全部话题 移民 创业 iOS Mac Objective-C Swift Android 招聘 求职

UILable怎么设置行高

langhua9527
langhua9527 发布于 2014年01月06日
无人欣赏。

设置行高之后,怎么又在UITableViewCell里面计算高度的时候计算准确 计算高度我是这样计算的 [content sizeWithFont:XYXYSYSTEMMedium_FONT(14) constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap];

共3条回复
楼长 ·
xieweizhi007 回复于 2014年01月06日

貌似sizeWithFont: 在iOS7已经deprecated了吧.

heightForCell方法里计算UILabel的高度,然后返回cell的高度.

参看

2楼 ·
langhua9527 回复于 2014年01月06日

的确deprecated,但是还能用的。虽然警告

注意啊,我想设置的是UILable的行高啊。。。不是CELL的高度。。。 UILable的行高做好了,再去算CELL的高度

3楼 ·
xieweizhi007 回复于 2014年01月06日

貌似这个可以吧

+ (CGFloat)heightOfCellWithIngredientLine:(NSString *)ingredientLine
 withSuperviewWidth:(CGFloat)superviewWidth {
 CGFloat labelWidth = superviewWidth - 30.0f;
 // use the known label width with a maximum height of 100 points
 CGSize labelContraints = CGSizeMake(labelWidth, 100.0f);
 NSStringDrawingContext *context = [[NSStringDrawingContext alloc] init];
 CGRect labelRect = [ingredientLine boundingRectWithSize:labelContraints
 options:NSStringDrawingUsesLineFragmentOrigin
 attributes:nil
 context:context];
 // return the calculated required height of the cell considering the label
 return labelRect.size.height;
} 
登录 或者 注册

AltStyle によって変換されたページ (->オリジナル) /