Не добавляйте пунктирную границу в ячейку внутри класса UIViewController. Создайте подкласс для класса UITableViewCell и добавьте в него пунктирную границу. Затем переопределите метод layoutSublayers of layer
и обновите в нем рамку borderLayer.
![enter image description here](https://i.stack.imgur.com/rcQhd.gif)
class MyCell: UITableViewCell {
let borderLayer = CAShapeLayer()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
commonInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
}
func commonInit() {
selectionStyle = .none
layer.cornerRadius = 15.0
layer.masksToBounds = true
borderLayer.strokeColor = UIColor.black.cgColor
borderLayer.lineDashPattern = [4, 4]
borderLayer.fillColor = nil
self.layer.addSublayer(borderLayer)
}
override func layoutSublayers(of layer: CALayer) {
super.layoutSublayers(of: layer)
borderLayer.frame = self.bounds
borderLayer.path = UIBezierPath(roundedRect: self.bounds, cornerRadius: 15).cgPath
}
}
Проверьте раздел в методе cellforrow
и удалите этот пользовательский класс только для определенного раздела
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if [indexPath.section].sectionName == "DRAFT" {
let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell") as? MyCell
return cell
} else {
//... Other type cells
}
}