如何在 UITableViewCell 之间添加间距 [英] How to add spacing between UITableViewCell

查看:43
本文介绍了如何在 UITableViewCell 之间添加间距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在UITableViewCell之间增加间距?

Is there any way to add spacing between UITableViewCell?

我创建了一个表格,每个单元格只包含一个图像.像这样将图像分配给单元格:

I have created a table and each cell only contain an image. The image is assigned to the cell like this:

cell.imageView.image = [myImages objectAtIndex:indexPath.row];

但这会使图像放大并适合整个单元格,并且图像之间没有间距.

but this make the image enlarged and fit into the whole cell, and there are no spacing between the images.

或者这样说,图像的高度是例如50,我想在图像之间添加 20 个间距.有什么办法可以做到这一点吗?

Or lets say in this way, the height of image are e.g. 50, and I want to add 20 spacing between the images. Is there any way to accomplish this?

推荐答案

我使用 Swift 的简单解决方案:

My easy solution using Swift :

// Inside UITableViewCell subclass

override func layoutSubviews() {
    super.layoutSubviews()

    contentView.frame = contentView.frame.inset(by: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10))
}

结果

这篇关于如何在 UITableViewCell 之间添加间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆