我有一个 UITableView
,我正在添加从 xib 加载的 tableFooterView
。
var footer = NSBundle.mainBundle().loadNibNamed("AFooterView", owner: self, options: nil).first as! AFooterView
self.tableView.tableFooterView = footer
这很好用,但我需要能够设置此页脚的高度。 xib 只有一个垂直和水平居中的 UIImageView
,所以它会适应任何高度的 View 。
我不知道如何使用 AutoLayout
做到这一点?正确的道路是什么?
最佳答案
很抱歉造成混淆,这是更新后的答案:
我知道你可以通过设置框架高度来做到这一点,但它也可以通过在你的 imageView 完成加载后重新分配页脚 View 来使用自动布局。
// either let auto layout calculate the frame, or set the frame yourself
// I set the width to an arbitrary size but it doesn't seem to matter,
// it will automatically be adjusted by the tableview when you assign it
CGFloat width = 100;
CGFloat height = 500;
footerView.frame = CGRectMake(0, 0, width, height);
// this is the "trick": re-assign the footerView after its size has been updated
// so that the tableView will show it correctly
tableView.tableFooterView = footerView;
有关详细信息,请参阅 Resizing a UITableView’s tableHeaderView
原来的回答讲的是节页脚,不是表格 View 页脚
关于ios - 如何将高度设置为从 xib 加载的 tableFooterView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30989841/