UITableView中cell线条的自定义 表格分割线(swift OC)
来源:互联网 发布:android soctet编程 编辑:程序博客网 时间:2024/05/02 07:31
2.1通栏设置
通栏即UITableView的线条左右端间距都为0的情况,通栏的设置需要分别设置UITableView及UITableViewCell的layoutMargins属性
第一步设置UITableView
1
tableView.layoutMargins = UIEdgeInsetsZero
第二步设置UITableViewCell
1
tableViewCell.layoutMargins = UIEdgeInsetsZero
2.2线条左右等间距
左右等间距,分两种情况,一种间距大于系统默认左端间距,一种为小于系统默认左端艰巨
大于系统默认左端间距时,直接设置UITableview属性
(这个地方OC同样可以设置想要的cell线条,或者通过线条的长度吧把其隐藏)
1
tableView.separatorInset = UIEdgeInsetsMake(0, 20, 0, 20)
小于系统默认左端间距时,则多增加一个步骤:
* 按2.1先设置成通栏* 再按上面步骤设置UITableView的separatorInset属性
2.3Group风格扁平化
UITableView的plain style默认为扁平化风格,这里介绍group style如何进行扁平化设置。添加扩展:
123456789101112131415161718192021222324252627282930313233343536373839404142434445
extension UITableView { private var FLAG_TABLE_VIEW_CELL_LINE: Int { get { return 977322 } } //自动添加线条 func autoAddLineToCell(cell: UITableViewCell, indexPath: NSIndexPath, lineColor: UIColor) { let lineView = cell.viewWithTag(FLAG_TABLE_VIEW_CELL_LINE) if self.isNeedShow(indexPath) { if lineView == nil { self.addLineToCell(cell, lineColor: lineColor) } } else { lineView?.removeFromSuperview() } } private func addLineToCell(cell: UITableViewCell, lineColor: UIColor) { let view = UIView(frame: CGRectMake(0, 0, self.bounds.width, 0.5)) view.tag = FLAG_TABLE_VIEW_CELL_LINE view.backgroundColor = lineColor cell.contentView.addSubview(view) } private func isNeedShow(indexPath: NSIndexPath) -> Bool { let countCell = self.countCell(indexPath.section) if countCell == 0 || countCell == 1 { return false } if indexPath.row == 0 { return false } return true } private func countCell(atSection: Int) -> Int { return self.numberOfRowsInSection(atSection) } }
2.3.1代码设置
第一步,设置UITableView的separatorStyle属性
1
tableView.separatorStyle = .None
第二步,设置Cell
123456789
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier(ILTableView_Cell) //省略逻辑... //设置 tableView.autoAddLineToCell(cell!, indexPath: indexPath, lineColor: UIColor.lightGrayColor()) return cell!}
2.3.2 Storyboard设置
新建自定义类,ILTableViewController
1234567891011
class ILTableViewController: UITableViewController { override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = super.tableView(tableView, cellForRowAtIndexPath: indexPath) //设置 tableView.autoAddLineToCell(cell, indexPath: indexPath, lineColor: UIColor.lightGrayColor()) return cell }}
在storybarod中找到Controller中的class属性,设置为ILTableViewController,并修改UITableView的separatorStyle为None
0 0
- UITableView中cell线条的自定义 表格分割线(swift OC)
- iOS8中UITableVIew cell间分割线短的问题
- iOS uitableview中cell的分割线紧贴左边
- UITableView的cell的分割线位置
- UITableView 隐藏空白cell的分割线
- UITableView取消某一个cell的分割线
- UITableView 隐藏多余Cell的分割线
- iOS中 自定义cell分割线/分割线偏移
- 自定义cell分割线
- iOS中 自定义cell分割线/分割线偏移 韩俊强的博客
- UITableView 自定义分割线
- UITableView 自定义cell添加UIView作为分割线,选中消失的问题
- UITableView的cell的分割线的问题
- iOS开发中设置UITableView每组头试图与第一行cell之间的分割线
- 添加UIview自定义的分割线、去掉默认的cell分割线、默认选中某一个(行)cell的方法
- UITableView如何让cell的分割线左边不缩进
- UITableView不弹动,分割线颜色,cell的高度
- UITableView如何让cell的分割线左边不缩进
- 前端解决跨域问题的8种方案(最新最全)
- SpringMVC-@RequestMapping的参数和用法
- leecode 解题总结:109. Convert Sorted List to Binary Search Tree
- 猎头日记 每日一篇
- 为什么 CPU 等的频率可以达到 GHz 级,但一般的 FPGA 芯片的频率只能在百 MHz 级呢?
- UITableView中cell线条的自定义 表格分割线(swift OC)
- 同余
- 成为一个Java的架构师要学习哪些知识?
- CODEVS 1475 m进制转十进制
- OpenCV编译
- Android 水波纹显示进度效果
- 泛型接口和方法
- 【Unity&NGUI】圆环血条制作&以及多层圆环血条的实现
- node.js学习之module调用方式