gpt4 book ai didi

ios - UITableViewAutomaticDimension 不适用于 iOS8 中的页脚

转载 作者:技术小花猫 更新时间:2023-10-29 11:03:21 24 4
gpt4 key购买 nike

我在 UITableView 中有一个页脚。页脚只包含一个 UILabel,我想根据 UILabel 调整页脚高度,所以我使用了

self.tableview.estimatedSectionFooterHeight = 140;
self.tableview.sectionFooterHeight = UITableViewAutomaticDimension;

它在 iOS9 上运行良好,但在 iOS8 上运行不佳 enter image description here

这是我的页脚 View enter image description hereUILabel 具有约束:top=5, leading/trailing=8, bottom=34, line=0, height >= 18

这是我的初始化页脚代码

- (UIView *) tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
NSArray* nibViews = [[NSBundle mainBundle] loadNibNamed:@"BaseFooterViewCell" owner:self options:nil];
BaseFooterViewCell *myFooterView = [nibViews objectAtIndex: 0];
myFooterView.contentLabel.text = @"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.";
return myFooterView;
}

如何让它在 iOS8 中运行?任何帮助或建议将不胜感激。
如果您无法理解我的问题,请查看DEMO PROJECT

更新在某些情况下,我的页脚会更复杂,它不仅包含一个UILabel,而且UILabelUIButton也会有不同的大小iPhoneiPad。因此,很难正确计算页脚高度。我仍然想使用 UITableViewAutomaticDimension

最佳答案

你可以用这个 -

-(CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section{
// return 43;

CGSize constraint = CGSizeMake(width, 20000.0f);
CGSize size;

CGSize boundingBox = [text boundingRectWithSize:constraint
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName:font}
context:nil].size;

size = CGSizeMake(ceil(boundingBox.width), ceil(boundingBox.height));

return size.height;
}

请尝试一下,它对我有用,或者随意。

关于ios - UITableViewAutomaticDimension 不适用于 iOS8 中的页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37517028/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com