Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 设置单元格背景视图后UITableViewCells之间的垂直间距_Ios_Uitableview - Fatal编程技术网

Ios 设置单元格背景视图后UITableViewCells之间的垂直间距

Ios 设置单元格背景视图后UITableViewCells之间的垂直间距,ios,uitableview,Ios,Uitableview,我正在实现UITableViewCells,它具有自定义背景并在点击时展开 我正在将自定义视图设置为我的UITableViewCells背景视图:(在RowForIndexPath中) 这很好,通过设置backgroundView而不是contentView,“我的backgroundView”可以缩放以适应单元格扩展后的新大小(轻触后更改RowAtIndexPath的高度) 我现在的问题是,我希望我的细胞之间有几个像素的垂直空间。使用上述方法将使圆形黑色单元格“背靠背”显示 是否有办法在单元格

我正在实现UITableViewCells,它具有自定义背景并在点击时展开

我正在将自定义视图设置为我的UITableViewCells背景视图:(在RowForIndexPath中)

这很好,通过设置backgroundView而不是contentView,“我的backgroundView”可以缩放以适应单元格扩展后的新大小(轻触后更改RowAtIndexPath的高度)

我现在的问题是,我希望我的细胞之间有几个像素的垂直空间。使用上述方法将使圆形黑色单元格“背靠背”显示

是否有办法在单元格之间添加垂直空间,或者是否有完全不同的方法来获得所需的单元格外观?


提前感谢。

为了显示单元格之间的空间并避免出现“背靠背”问题,您可以使用以下帧添加
UIView
,即
CGRectMake(0,0320,1)
并将背景设置为浅灰色作为标准单元格分隔符,或者如果您只需要一些填充,则可以使背景清晰

就我个人而言,我喜欢使用interface builder,但您当然可以通过编程实现

UIView *cellSeparator = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320 ,1)];
[cellSeparator setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin |
                                   UIViewAutoresizingFlexibleRightMargin | 
                                   UIViewAutoresizingFlexibleWidth];       
[cellSeparator setContentMode:UIViewContentModeTopLeft];    
[cellSeparator setBackgroundColor:[UIColor lightGrayColor]];
[cell addSubview:cellSeparator];
[cellSeparator release];

我之所以在单元格顶部设置cellSeparator,是因为其效果实际上是针对位于第一行和最后一行之间的单元格。此外,设置autoresizingMask和contentMode也很重要,以确保在对
UITableViewCell
进行大小更改时单元格分隔符能够正确调整。如果单元格中有任何元素的起始位置为x=0 y=0,则需要将它们向下移动到单元格分隔符的高度,再加上一些额外的像素进行填充,以便分隔符不会穿过单元格中的任何元素。

我不确定您要查找的内容,但为了参考,请检查以下内容:
UIView *cellSeparator = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320 ,1)];
[cellSeparator setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin |
                                   UIViewAutoresizingFlexibleRightMargin | 
                                   UIViewAutoresizingFlexibleWidth];       
[cellSeparator setContentMode:UIViewContentModeTopLeft];    
[cellSeparator setBackgroundColor:[UIColor lightGrayColor]];
[cell addSubview:cellSeparator];
[cellSeparator release];