当前位置: 首页 > news >正文

UITableView自定义TableHeader和TableFooter

UITableView自定义TableHeader和TableFooter

    • 我猜你希望的效果是这样的

我猜你希望的效果是这样的

在这里插入图片描述

自定义页眉视图
让我们创建一个文件名 UITableViewHeaderFooterView 的 CustomerHeaderView 子类。
在这里插入图片描述
现在让我们创建视图的 Xib 文件并将其命名为 CustomHeaderView。

在这里插入图片描述

更改高度标题视图在创建的 XIB 文件中选择视图。在属性检查器中选择大小并将其大小设置为自由度

在这里插入图片描述

自定义页脚视图 让我们创建一个文件名 UITableViewHeaderFooterView 的客户页脚视图
子类并重复上述步骤。

在主类文件中,寄存器头视图和页脚视图在视图中的表视图DidLoad

class ViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
tableView.register(UINib(nibName: "CustomHeaderView", bundle: nil), forHeaderFooterViewReuseIdentifier: "CustomHeaderView")
tableView.register(UINib(nibName: "CustomFooterView", bundle: nil), forHeaderFooterViewReuseIdentifier: "CustomFooterView")}
}
 func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {let indentifier = "CustomHeaderView"let cell = tableView.dequeueReusableHeaderFooterView(withIdentifier: indentifier)if section == 0 {cell?.contentView.backgroundColor = .cyan}if section == 1 {cell?.contentView.backgroundColor = .red}return cell}func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {let indentifier = "CustomHeaderView"let cell = tableView.dequeueReusableHeaderFooterView(withIdentifier: indentifier)cell?.contentView.backgroundColor = UIColor.tableSectionColor()return cell}func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {return 100}func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {return 50 }
http://www.lryc.cn/news/136976.html

相关文章:

  • 【TA 挖坑03】雾效 | 透光材质 | Impostor | 厚度转球谐
  • 案例-基于MVC和三层架构实现商品表的增删改查
  • Java——一个简单的计算器程序
  • 自定义滑动到底部触发指令,elementUI实现分页下拉框
  • 【Windows 常用工具系列 10 -- linux ssh登录脚本输入密码】
  • C#的索引器
  • 软件配置安装(破解)--- maven下载配置
  • python解析小说
  • SQL Server 执行报错: “minus“ 附近有语法错误。
  • kali linux查看局域网下所有IP,并对指定IP攻击
  • 基于QCC_BES 平台的LMS自适应滤波算法实现
  • 大疆飞卡30运载无人机技术分享
  • 单片机的串口通信
  • 【C/C++】STL学习所得
  • leetcode几个数组题
  • 【LeetCode】模拟实现FILE以及认识缓冲区
  • 【Terraform学习】使用 Terraform 将 EC2 实例作为 Web 服务器启动(Terraform-AWS最佳实战学习)
  • WebGL 变量uniform、gl.getUniformLocation、gl.uniform4f及其同族函数相关
  • 【Visual Studio】生成.i文件
  • 本地生活服务平台加盟哪家公司好?
  • css-grid使用
  • springBoot提取一个List<?>中的某个字段集合
  • 【BUG】 ‘cv2.cv2‘ ‘wechat_qrcode_WeChatQRCode‘
  • 10 Mybatis
  • 【PHP】PHP的面向对象编程
  • Windows10突然出现音频无法正常运行的解决方法
  • Maven面试题大全及答案
  • 探究字符串匹配算法:暴力法与KMP算法的Java实现
  • 前端面试:【浏览器与渲染引擎】工作原理与渲染流程
  • PySide6学习笔记--gui小模版使用