作者热门文章
- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
我在 UITableView
中有一个页脚。页脚只包含一个 UILabel
,我想根据 UILabel
调整页脚高度,所以我使用了
self.tableview.estimatedSectionFooterHeight = 140;
self.tableview.sectionFooterHeight = UITableViewAutomaticDimension;
这是我的页脚 View UILabel
具有约束: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
,而且UILabel
、UIButton
也会有不同的大小iPhone
和 iPad
。因此,很难正确计算页脚高度。我仍然想使用 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/
我是一名优秀的程序员,十分优秀!