单元格之间的UITableviewcell间距 [英] UITableviewcell spacing between cells

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

问题描述

我动态创建 UITableView 单元格并在其上添加三个标签。我通过 opaque no和clearcolor 使我的表格变得透明。
但是细胞显示没有空间。我需要在细胞之间留出空间。
实际上如果我从xib文件加载自定义 UITableViewCell ,空间会自动出现。如何解决这个问题?

I am creating UITableView cells dynamically and adding three labels on to it.I made my table as transparent by opaque no and clearcolor. But the cells are being shown without spaces.I need to give space between cells. Actually if i load a custom UITableViewCell from the xib file the space comes automatically. How to solve this issue?

推荐答案

带自定义间距的UITableView



您可以通过欺骗tableView单元格来完成此操作。默认情况下,您只能指定一行,蚀刻线或无,所以这里是一个替代方案。你需要覆盖tableView委托方法:

UITableView with custom spacing

You can do this by cheating the tableView cell. By default you can only specify a single line, etched line or none so here is an alternative. You'll need to override the tableView delegate method:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

计算单元格高度及其内容,边距/填充/线宽并返回。将单元格的背景颜色设置为 [UIColor clearColor] ,并使表格背景成为分隔符所需的颜色。子类UITableViewCell并附加backgroundContainerView并使其成为您单元格所需的背景颜色。将所有子视图附加到该backgroundContainerView。

Calculate your cell height with its contents, margin/padding/line width and return it. Set the background color of the cell to [UIColor clearColor] and make your table background the desired color for your separator. Subclass UITableViewCell and attach a backgroundContainerView and make it the desired background color for your cell. Attach all the subview to that backgroundContainerView.

最后,在UITableViewCell子类中实现

Finally, in the UITableViewCell subclass implement

- (void)layoutSubviews

在这里,您应该使用容器视图布局子视图,就像在这就是整个细胞。

Here you should layout the subviews with the container view as if that is the whole cell.

这篇关于单元格之间的UITableviewcell间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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