[英]Add a Section Separator Between UITableView
The first one(left) is my design and the second one(right) is what I have achieved still now.第一个(左)是我的设计,第二个(右)是我现在已经取得的成果。 One difference is that for the second image I don't have the separator line like the first one.
一个区别是,对于第二张图像,我没有像第一张那样的分隔线。 In
viewForFooterInSection
i have already tried many existing solutions to show separator lines but didn't get the exact solution.在
viewForFooterInSection
我已经尝试了许多现有的解决方案来显示分隔线,但没有得到确切的解决方案。 I need the separator line at the end of the last row of the first and second sections with some space.我需要在第一部分和第二部分的最后一行末尾有分隔线,并留有一些空间。
Here is my code -这是我的代码 -
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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.