[英]iOS >7 - Table text is getting cut off
这是我的代码:
- (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) AutoLayout或AutoResize问题,即设置不正确。
2)在heightForRowAtIndexPath
返回的高度错误。
说明 :在这里,您应该返回高度(文本高度+顶部填充+底部填充)
return = textRect.size.height+(2*label.frame.origin.x);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.