我的问题类似于this所以问题。
我的 UITableViewCell Height
在 IOS8
上完美工作。 IOS7
问题高度增加但内容不显示。
我的代码是:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
long hightmain=0;
if(selectIndex && indexPath.section == selectIndex.section)
{
NSString * myString = [description_vegetable_array objectAtIndex:indexPath.section];
CGSize labelSize = [myString sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(190, MAXFLOAT) lineBreakMode:NSLineBreakByWordWrapping];
hightmain=labelSize.height+120;
if (hightmain<=140)
{
btn11.frame=CGRectMake(240,100,70,17);
Description_LBL.frame=CGRectMake(127, 0, 190, 140);
BGImage.frame=CGRectMake(0, -3, 320, 140);
}
else
{
[btn11 setTitle:@"Less Info" forState:UIControlStateNormal];
btn11.frame=CGRectMake(240,hightmain-30,70,17);
Description_LBL.frame=CGRectMake(127, -20, 190, hightmain);
BGImage.frame=CGRectMake(0, -3, 320, hightmain);
return hightmain;
}
}
else
{
return 140;
}
}
Description_LBL.frame=CGRectMake(127, 0, 190, 140);
我的标签高度增加但文本不显示....在 IOS8 中完全工作但 IOS7 不工作
最佳答案
使用 boundingRectWithSize:
which NSString public methods that calculates the size based on a string value.
例子
[testString boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width,MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil]
注意: sizeWithFont:在 iOS 7.0 中已弃用
关于ios - UITableview 单元格高度在 IOS7 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28298076/