Tableview单元格的填充和间距

我有一张桌子,桌子上有一些图片和文字

Tableview单元格的填充和间距

我想做的第一件事是在单元格中添加填充,以使带有圆圈和剪刀的图像不会碰到单元格的边界。我已经尝试过诸如cell.layoutMargins = UIEdgeInsets(top: 50,left: 50,bottom: 50,right: 50)cell.bounds = CGRect(x: 0,y: 0,width: 100,height: 100)cell.separatorInset = UIEdgeInsets(top: 100,left: 100,bottom: 100,right: 100)之类的东西,但没有任何改变。

我想要的第二件事是在单元格之间添加一个间距,我尝试了所有发现的解决方案,但似乎不起作用

代码(我尝试过的一些解决方案都是一起编写的,但是我也一次尝试过它们)

    func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "difficultyCell",for: indexPath)
        cell.textLabel?.text = myDict[indexPath.row].key 
        cell.textLabel?.font = .boldSystemFont(ofSize: 20)
        let imageCell = UIImage(named: "scissors.png")
        cell.imageView?.image = imageCell
        cell.backgroundColor = Esercizio.hexStringToUIColor(hex: "#4cf584").withAlphaComponent(0.85)
        cell.layer.borderColor = UIColor.orange.cgColor
        cell.layer.borderWidth = 1
        cell.layer.cornerRadius = 8
        cell.layoutMargins = UIEdgeInsets(top: 50,right: 50)
        cell.bounds = CGRect(x: 0,height: 100)
        cell.separatorInset = UIEdgeInsets(top: 100,right: 100)
        return cell
    }
we12q 回答:Tableview单元格的填充和间距

这里最好的解决方案是在contentView中创建自己的单元格,添加自己的图像,标签等,并使用自动布局约束对它们进行调整。

请参阅:https://www.raywenderlich.com/8549-self-sizing-table-view-cells

本文链接:https://www.f2er.com/3143134.html

大家都在问