ios - 如何将高度设置为从 xib 加载的 tableFooterView

标签 ios uitableview cocoa-touch autolayout

我有一个 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/

相关文章:

php - 如何 POST 自定义 NSObject 属性以保存 MySQL

iphone - 在 Xcode 4.2 上将 iOS 5 应用程序更新为通用?

iOS UITableView contentOffset 当键盘显示时

iphone - 为什么 UIView 的边界是 CGRect 而不是 CGSize?

ios - Appcelerator - Xcode EULA 尚未被接受。启动 Xcode 并接受许可证

javascript - 在 iPad 上,如何在不显示选项的情况下通过 Javascript 事件在选择元素上设置 focus()?

ios - 根据在同一主视图中的文本字段中输入的文本更新 UITableView 单元格

ios - 单元格背景视差就像 iOS7 天气应用程序中一样

iphone - 在 IB 中编辑 UIScrollView 的最简单方法

ios - 如何推送两个 View Controller 但只为第二个设置动画过渡?