How to give space between two cells in tableview?

前端 未结 26 1483
谎友^
谎友^ 2020-11-29 00:11

I want a space between two cell in table view,

I want cell like this,

\"enter<

26条回答
  •  眼角桃花
    2020-11-29 00:43

    best way to do that use xib file and give top and bottom constraint to it. for example, here I give bottom constraint 10 and make sure give perfect height to cell as shown as given below.here in code 'joinTableViewCell' is fileName of xib file.

    enter image description here

    extension JoinTableViewController: UITableViewDataSource,UITableViewDelegate {
        
        
        func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return 4
        }
        
        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            let cell = Bundle.main.loadNibNamed("joinTableViewCell", owner: self, options: nil)?.first as! joinTableViewCell
            cell.ImgView.layer.masksToBounds = true
            cell.ImgView.cornerRadius(cell.ImgView.bounds.width / 2)
            cell.lblName.text = "Christian Bell"
            cell.lblJoin.text = "Joined"+"\t"+"Sep 3"
            return cell
        }
        
        func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
            return 90
        }
        
        
        
    }

提交回复
热议问题