在TableView中的两个单元格之间添加填充

发布于 2025-02-05 04:43:45 字数 1147 浏览 1 评论 0原文

使用WebSocket创建了一个基本的聊天应用程序,为了正确的外观,我想给每个单元格一点一点填充。但是,确实不知道该如何做到当前在下面的解决方案下尝试的方法,但它只会给我“我想要“外部填充”的“内部”填充

尝试

导入uikit

class CellView: UITableViewCell {

    override func awakeFromNib() {
        super.awakeFromNib()
        super.layoutSubviews()
        self.backgroundColor = .systemBlue
        self.layer.cornerRadius = 10
       
      
      
    }
    override func layoutSubviews() {
        super.layoutSubviews()

        contentView.frame = contentView.frame.inset(by: UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8))
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return CGFloat(15.0)
    }
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        let v = UIView()
        v.backgroundColor = .clear
        return v
    }

created a basic chat application using websocket, and for a proper look I want to give my each cell a little bit padding. But really couldn't figure out how to do that currently tried below solution but it only gives padding "inside my cell" which I want "outside padding"

tried

import UIKit

class CellView: UITableViewCell {

    override func awakeFromNib() {
        super.awakeFromNib()
        super.layoutSubviews()
        self.backgroundColor = .systemBlue
        self.layer.cornerRadius = 10
       
      
      
    }
    override func layoutSubviews() {
        super.layoutSubviews()

        contentView.frame = contentView.frame.inset(by: UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8))
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}

tried

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return CGFloat(15.0)
    }
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        let v = UIView()
        v.backgroundColor = .clear
        return v
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘦怹 2025-02-12 04:43:45

没有像uitableview中的单元格之间的空间这样的概念。

最好的选择是将填充物添加到单元本身的内容中。

因此,与其具有具有内容高度80的高度80的单元格。将行高度更改为100,并将内容保持在80的高度。

通过这样做,您现在已经在每个单元格之间创建了一个20的“空间”。

There is no such concept as the space between cells in UITableView.

Your best bet is to add padding to the content of the cell itself.

So, instead of having a cell of height 80 with content height 80. Change the row height to 100 and keep the content at height 80.

By doing that you now have created a “space” of 20 between each cell.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文