我尝试使用以下代码向UITableViewCells
绘制虚线底部边框:
func addDashedBottomBorder(to cell: UITableViewCell) {
let width = CGFloat(2.0)
let dashedBorderLayer: CAShapeLayer = CAShapeLayer()
let frameSize = cell.frame.size
let shapeRect = CGRect(x: 0, y: frameSize.height, width: frameSize.width*2, height: 1)
dashedBorderLayer.bounds = shapeRect
dashedBorderLayer.position = CGPoint(x: 0, y: frameSize.height)
dashedBorderLayer.strokeColor = UIColor.lightGray.cgColor
dashedBorderLayer.lineWidth = width
dashedBorderLayer.lineDashPattern = [9, 6]
dashedBorderLayer.path = UIBezierPath(roundedRect: shapeRect, cornerRadius: 5).cgPath
cell.layer.addSublayer(dashedBorderLayer)
}
但是,我在虚线后面有一条奇怪的实线,如下所示:http://imgur.com/6kR9PgZ
我已在tableView.separatorColor = UIColor.clear
viewDidLoad
任何想法为什么我在虚线之后得到那条实线?
答案 0 :(得分:3)
试试这个
func addDashedBottomBorder(to cell: UITableViewCell) {
let color = UIColor.lightGray.cgColor
let shapeLayer:CAShapeLayer = CAShapeLayer()
let frameSize = cell.frame.size
let shapeRect = CGRect(x: 0, y: 0, width: frameSize.width, height: 0)
shapeLayer.bounds = shapeRect
shapeLayer.position = CGPoint(x: frameSize.width/2, y: frameSize.height)
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.strokeColor = color
shapeLayer.lineWidth = 2.0
shapeLayer.lineJoin = kCALineJoinRound
shapeLayer.lineDashPattern = [9,6]
shapeLayer.path = UIBezierPath(roundedRect: CGRect(x: 0, y: shapeRect.height, width: shapeRect.width, height: 0), cornerRadius: 0).cgPath
cell.layer.addSublayer(shapeLayer)
}
输出
答案 1 :(得分:2)
如果你写了
tableView.separatorStyle = .None
仍然,哟在破旧模式下面得到一条实线然后100%它不是tableview分隔符。这是其他的东西
检查表背景颜色,清除分隔符颜色时,a 细胞之间仍留有小空间。如果你细胞背景颜色 从表背景颜色不同的颜色,它看起来像一个 分离器。
答案 2 :(得分:1)
目标-C
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
在Swift中
tableView.separatorStyle = .None
答案 3 :(得分:1)