我们上一节主要讲了tableView分区以及分区的头标题和尾标题
继续使用上节代码(代码下载方式见第五节末尾)
上节我们讲了设置分区头标题。其实分区头 还可以设置高度,还有自定义view等功能
接下来我们尝试设置一下头视图的高度
很简单,实现一个代理方法
- func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
- return 68
- }
我们已经看到分区头高度明显增加了
分区尾也有同样的功能,大家尝试一下(如有问题加群讨论:492222303)
接下来我们看下自定义头视图的view
- //设置头视图的View
- func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
- let view=UIView()
- view.backgroundColor=UIColor.lightGrayColor()
- let textF=UITextField(frame: CGRectMake(10, 1, 120, 20))
- textF.text="测试"
- view.addSubview(textF)
- return view
- }
看下效果