分组的UITableview删除外部分隔线 [英] Grouped UITableview remove outer separator line
问题描述
我有一个以编程方式创建的分组的UITableview.另外,我还有一个以编程方式在tableview中填充的xib文件的单元格.到目前为止,一切都很好.但是我只想删除外部分隔线.我使用下面的代码,但是这次删除了所有分隔线.
I have a grouped UITableview which is created programatically. Also I have a cell with xib file populated in tableview programmatically as well. So far so good. But I want to only remove outer separator line. I used below code but this time removed all separator line.
self.tableView.separatorColor = [UIColor clearColor];
self.tableView.separatorColor = [UIColor clearColor];
对于我的情况,这不是一个好选择.这是我想做的屏幕截图;
this is not good option for my situation. Here is the screenshot what i want to do;
推荐答案
我刚刚制定了一个解决方案,因为单元格具有contentView
,它是UIView
,所以我认为您可以专注于contentView
.
I just worked out a solution, as the cell has contentView
which is a UIView
, so I think you can just focus on the bottomline of contentView
.
这是我的代码:
首先,您必须清除分隔符
first, you have to make the separator to clear
tableView.separatorColor = UIColor.clear
第二,在cellForRowAt
函数中:
let bottomBorder = CALayer()
bottomBorder.frame = CGRect(x: 0.0, y: 43.0, width: cell.contentView.frame.size.width, height: 1.0)
bottomBorder.backgroundColor = UIColor(white: 0.8, alpha: 1.0).cgColor
cell.contentView.layer.addSublayer(bottomBorder)
在这里您将看到这样的用户界面:
here you will see the UI like this:
这篇关于分组的UITableview删除外部分隔线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!