遇到了需要自适应高度,在iOS6好用的代码在iOS7上被废弃了,下面是在stackoverflow收集到的解决办法。
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) { CGSize size = CGSizeMake(230,9999); CGRect textRect = [specialityObj.name boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont fontWithName:[AppHandlers zHandler].fontName size:14]} context:nil]; total_height = total_height + textRect.size.height; } else { CGSize maximumLabelSize = CGSizeMake(230,9999); expectedLabelSize = [specialityObj.name sizeWithFont:[UIFont fontWithName:[AppHandlers zHandler].fontName size:14] constrainedToSize:maximumLabelSize lineBreakMode:UILineBreakModeWordWrap]; //iOS 6 and previous. total_height = total_height + expectedLabelSize.height; }
原文:http://www.cnblogs.com/marvindev/p/adaptive.html