ios - 在 UITableView 之间添加分节分隔符
问题描述
第一个(左)是我的设计,第二个(右)是我现在已经取得的成果。一个区别是,对于第二张图像,我没有像第一张那样的分隔线。在viewForFooterInSection
我已经尝试了许多现有的解决方案来显示分隔线,但没有得到确切的解决方案。我需要在第一部分和第二部分的最后一行末尾有分隔线,并留有一些空间。
这是我的代码 -
func numberOfSections(in tableView: UITableView) -> Int {
return secName.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return items[section].count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "APHomeTableViewCell", for: indexPath) as! APHomeTableViewCell
cell.selectionStyle = .none
cell.cellTitle.text = items[indexPath.section][indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return self.secName[section]
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
self.tableView.backgroundColor = UIColor.white
let headerFrame = tableView.frame
let title = UILabel()
title.frame = CGRect(x: 40, y: 0, width: headerFrame.size.width-20, height: 40)
title.font = UIFont.SFBoldFont(ofSize: 14)//UIFont(name: "Futura", size: 30)!
title.text = self.tableView(tableView, titleForHeaderInSection: section)
title.textColor = UIColor(white: 0.19, alpha: 1.0)//UIColor(red: 34/255.0, green: 141/255.0, blue: 183/255.0, alpha: 1.0)
let headerView:UIView = UIView(frame: CGRect(x: 0, y: 0, width: headerFrame.size.width, height: headerFrame.size.height))
headerView.addSubview(title)
return headerView
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 45
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
let section = indexPath.section
return 70
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 50
}
解决方案
推荐阅读
- ssh - ssh config 给我一个错误,同时设置 cloudflared argo 隧道为什么?
- mysql - 如何从 laravel 查询生成器中的子查询中进行选择
- c++ - C ++ Thread_local类的非静态成员?
- ios - iOS 应用内购买介绍性免费试用,可访问部分内容
- vaadin - 是否可以将 Vaadin 协作引擎与 Fusion 结合使用?
- c# - 在 Asp.Net DependencyInjection 中注册一个接口对应的不同对象
- android - Android Gradle Sync“标签不匹配!” 错误
- html - 数据表引导对齐旋转标题
- react-data-grid - react-data-grid/addon 不适用于 react-data 网格
- java - VS Code Java 问题