How to increase the UITableView separator height?

后端 未结 17 2137
花落未央
花落未央 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 00:53

    In Swift

    The easiest and shortest way for me was to add the snippet below in cellForRowAtIndexPath or in willDisplayCell:

    override func tableView(tableView: UITableView,
                            willDisplayCell cell: UITableViewCell,
                            forRowAtIndexPath indexPath: NSIndexPath)
    {
            let additionalSeparatorThickness = CGFloat(3)
            let additionalSeparator = UIView(frame: CGRectMake(0,
                                                               cell.frame.size.height - additionalSeparatorThickness,
                                                               cell.frame.size.width,
                                                               additionalSeparatorThickness))
            additionalSeparator.backgroundColor = UIColor.redColor()
            cell.addSubview(additionalSeparator)
    }
    

提交回复
热议问题