我正在尝试将一个可点击的按钮和一些文本添加到UITableView中的部分页脚。我希望获得与iOS设置应用程序完全相同的结果(如屏幕截图中的“了解更多...”按钮)。
有谁知道Apple是如何做到的?
修改
抱歉,我添加的屏幕截图可能有点误导,因为我按住按钮同时使其更突出。这就是页脚的实际外观:
我尝试实现titleForFooterInSection,然后在willDisplayFooterView中向标准页脚标签添加手势识别器,但在初始调用时标签为nil。我不确定这是否是一个好的方法..
Split(chNum," ")(wordNumber - 1)
答案 0 :(得分:0)
Jsut使用viewForHeaderInSection
override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 150
}
override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let header = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 150));
header.backgroundColor = UIColor.groupTableViewBackground
let label = UILabel.init(frame: CGRect.init(x: 10, y: 10, width: tableView.frame.width-20, height: 100))
label.text = "I tried using your code, but the footer doesn't look like the one from my screenshot. Here's what I got: Screenshot I usually work with storyboards and xibs so I don't really know how to align the text and button"
label.numberOfLines = 4
header.addSubview(label)
let button = UIButton.init(frame: CGRect.init(x: ((tableView.frame.width-100) / 2), y: 90, width: 100, height: 40))
button.setTitle("LoadMore...", for: UIControlState.normal)
button.titleLabel?.font = UIFont.systemFont(ofSize: 12)
button.setTitleColor(.black, for: UIControlState.normal)
button.backgroundColor = .white
button.clipsToBounds = true
button.layer.cornerRadius = 20
header.addSubview(button)
return header
}