我想畫虛線下邊框到UITableViewCells
用下面的代碼:企圖拉攏虛線邊框的UITableViewCell
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)
}
但是,我得到我的虛線CAN背後一個奇怪的實線在這裏看到:http://imgur.com/6kR9PgZ
我已經在viewDidLoad
任何爲什麼我收到實線背後的虛線一個想法設置tableView.separatorColor = UIColor.clear
?
你檢查了答案 –