How to increase the UITableView separator height?

后端 未结 17 2206
花落未央
花落未央 2020-12-08 00:19

I want more space(10px) between each cell. How can I do this?

And I have added this code

tableView.separatorStyle = UITableViewCellSepar         


        
17条回答
  •  盖世英雄少女心
    2020-12-08 01:02

    this is quite old. Nevertheless I will post my approach.

    Simply increase your cell height a bit and assign a mask layer to the cell, like that:

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "...", for: indexPath)
    
        // Configure the cell...
        let maskLayer = CAShapeLayer()
        let bounds = cell.bounds
        maskLayer.path = UIBezierPath(roundedRect: CGRect(x: 2, y: 2, width: bounds.width-4, height: bounds.height-4), cornerRadius: 5).cgPath
        cell.layer.mask = maskLayer
    
        return cell
    }
    

    So in this example my seperator height will be 4.

    Have fun!

提交回复
热议问题