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

查看:106
本文介绍了如何在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?

推荐答案

我在单元格之间添加间距的方法是使numberOfSections =你的数组计数并使每个部分只包含一行。然后定义headerView及其高度。

The way I achieve adding spacing between cells is to make numberOfSections = "Your array count" and make each section contains only one row. And then define headerView and its height.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return yourArry.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return cellSpacingHeight;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *v = [UIView new];
    [v setBackgroundColor:[UIColor clearColor]];
    return v;
}

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

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