iOS UITableView自定义页脚与UIView

时间:2016-07-28 17:57:23

标签: ios swift uitableview uiview tableview

我想为我的UITableView制作一个自定义页脚。 为此,我将需要UITableView中最后一个单元格的位置,并在TableView下设置我的UIView。 但我不知道如何获得最后一个细胞的位置。

甚至可以制作这种自定义Tableview-footer?

2 个答案:

答案 0 :(得分:1)

您无需制作自定义页脚或了解最后一个单元格的位置。它已在 UITableViewDelegate 上提供。

您需要自定义 UIView ,然后在func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView?的回调中返回UIView。

示例:

func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    let view = UIView.init(frame: CGRectMake(0, 0, tableView.frame.size.width, tableView.frame.size.height))
    view.backgroundColor = UIColor.greenColor()
    return view
}

上面的代码将为您提供UITableView的绿色UIView。只需确保不在Storyboard或代码上将页脚高度设置为 0

答案 1 :(得分:1)

您可以直接在故事板或xib中添加页脚 - 只需拖动您的视图,使其内部},但之后>所有tableView的单元格。