iOS表视图分割线的总结
来源:互联网 发布:通过 相信 马克思 知乎 编辑:程序博客网 时间:2024/05/17 20:29
1.在自定义单元格的底部或者顶部画一条分割线,这种方法简单粗暴,而且可以在任意位置绘制,相对也比较灵活
let seperateLine = UILabel() seperateLine.backgroundColor=UIColor.groupTableViewBackground
2.利用SectionHead和SectionFoot的高度来实现
如果用这种方法来实现分割线的效果,一定要记住把UITableView的风格设置为grouped,因为plain类型UITableView的section会有一个悬停的效果,用户体验不好。但是,grouped类型默认是有节头和节脚高度的,所以需要自己设置高度,而且不能设置为0,因为设置为0的时候,也是默认高度,应该设置为0.001。
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { if section == 0 { return 0.001 } return 15.0 } func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { return 0.001} func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? { return ""}func tableView(_ tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) { let header = view as! UITableViewHeaderFooterView header.contentView.backgroundColor=UIColor.groupTableViewBackground}
ps:必须得给title赋值,否则view将为nil。通过这种方式也可以为系统的sctionHead或者sctionFoot设置背景颜色以及设置title的字体、颜色等。如果只设置section高度,不给title赋值,此时sctionHead或者sctionFoot为nil即不显示,所以我们看到的颜色将是tableview的背景颜色,通过该方式也可以形成分隔带。
3.自定义sctionHead或者sctionFoot
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { let view=UIView(frame: CGRect(x: 0, y: 0, width: Screen.Width, height: 1)) view.backgroundColor=UIColor.groupTableViewBackground return view}func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { return 1}
阅读全文
0 0
- iOS表视图分割线的总结
- iOS 8 setSeparatorInset 表视图显示全部的分割线 去除空白行的分割线
- 表视图去掉某一行的分割线
- iOS -- UITableViewCell的分割线
- ios TableViewCell的分割线
- iOS UITableViewCell的分割线缩进
- [iOS]创建单一像素的分割线
- iOS 画分割线的问题
- iOS tableView的分割线短一节
- iOS TableView的cell分割线格式
- iOS 自定义UITableViewCell的分割线
- iOS分割线的操作方式
- iOS tableView cell的分割线设置
- ios 横分割线 纵分割线
- iOS -- navigationBar分割线
- recyclerview分割线 -总结
- iOS-UItableview 分割线(自定义+原生)方法总结
- [iOS] 隐藏UITableView不需要的分割线(只显示有行内容的分割线)
- require.js用法详解
- 如何用proto生成文件
- DirectX11 使用Instancing技术提高重复模型的绘制效率
- Kotlin使用小结
- 我的英语之旅(开始)
- iOS表视图分割线的总结
- 底部导航栏
- 将所有异常打印到日志
- DateTimeField *** received a naive datetime (***) while time zone support is active
- java ssm框架学习——三大框架整合
- android studio中application module,library module,java module的区别
- Repeated DNA Sequences问题及解法
- Nginx负载均衡入门Demo
- PB用OLE创建Excel后,打开时却提示“您尝试打开的文件 的格式与文件扩展名指定的格式不一致”