iOS> 7 - 表格文字正在切断

时间:2015-03-10 14:48:15

标签: ios iphone uitableview

这是我的代码:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
        UIFont *cellFont;

        if(delegate.iPad){
            cellFont= [UIFont fontWithName:@"Helvetica" size:28.0];
        }else{
            cellFont= [UIFont fontWithName:@"Helvetica" size:12.0];
        }
        CGSize size = [cellText sizeWithAttributes:@{NSFontAttributeName: myFont}];

        // Values are fractional -- you should take the ceilf to get equivalent values
        CGSize labelSize = CGSizeMake(ceilf(size.width), ceilf(size.height));
        tableHeight2 = tableHeight2 + labelSize.height;


        NSStringDrawingContext *ctx = [NSStringDrawingContext new];
        NSAttributedString *aString = [[NSAttributedString alloc] initWithString:cellText];
        UITextView *calculationView = [[UITextView alloc] init];
        [calculationView setAttributedText:aString];
        CGRect textRect = [calculationView.text boundingRectWithSize:table2.frame.size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:cellFont} context:ctx];
        return = textRect.size.height;
}

文本的最后一行由于某种原因被切断,即使它似乎正在正确计算高度。我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

可能发生以下两个原因:

1) AutoLayout AutoResize 问题,即设置不正确。

2)heightForRowAtIndexPath中返回的高度是错误的。

解释:这里你应该返回高度(文字高度+顶部填充+底部填充)

 return = textRect.size.height+(2*label.frame.origin.x);