Ios 我如何实现像这样的UITableViewCell页边距(图)?

Ios 我如何实现像这样的UITableViewCell页边距(图)?,ios,objective-c,user-interface,uitableview,Ios,Objective C,User Interface,Uitableview,我非常喜欢在这个应用程序的UITableViewCells中添加填充的方式。我怀疑这在故事板中是可能的,但实现这一点的最佳方式是什么 使用故事板在iOS 7上使用UITableView可以实现这一令人生畏的布局。通过编程,只要有点耐心,就可以相当容易地完成 无论如何,考虑到单元格中的信息量,我会尝试使用UICollectionView和UICollectionViewFlowLayout来代替表。这可能会让事情变得更简单,因为您可以在故事板中设置单元格大小、节边距、项目之间的最小距离等。我想您可

我非常喜欢在这个应用程序的
UITableViewCell
s中添加填充的方式。我怀疑这在故事板中是可能的,但实现这一点的最佳方式是什么


使用故事板在iOS 7上使用
UITableView
可以实现这一令人生畏的布局。通过编程,只要有点耐心,就可以相当容易地完成


无论如何,考虑到单元格中的信息量,我会尝试使用
UICollectionView
UICollectionViewFlowLayout
来代替表。这可能会让事情变得更简单,因为您可以在故事板中设置单元格大小、节边距、项目之间的最小距离等。我想您可以在故事板中轻松地完成这项工作

只需添加一个自定义单元格,灰色背景。 在此基础上,添加一个子视图
UIView
,背景为白色,并对大小进行排列,使其在单元格内成为一个较小的矩形,从而获得此边距效果

然后在白色子视图上添加标签/图像视图,就可以了

这种方法有什么问题吗?
感觉有点像作弊,但为什么不呢?

您所需要的只是定制表格单元格并添加特定背景

@implementation CustomTableViewCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {

        <init your custom cell here> 

        UIView *bgView = [[UIView alloc] initWithFrame:self.bounds];
        CGRect whiteRect = CGRectInset(bgView.bounds, 10, 5);
        UIView *innerView = [[UIView alloc] initWithFrame:whiteRect];
        innerView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
        innerView.backgroundColor = [UIColor whiteColor];
        [bgView addSubview:innerView];
        bgView.backgroundColor = [UIColor colorWithRed:225.0/255 green:224.0/255 blue:230.0/255 alpha:1.0];
        self.backgroundView = bgView;

    }

    return self;
}
@实现CustomTableViewCell
-(id)initWithStyle:(UITableViewCellStyle)样式重用标识符:(NSString*)重用标识符{
if(self=[super initWithStyle:style-reuseIdentifier:reuseIdentifier]){
UIView*bgView=[[UIView alloc]initWithFrame:self.bounds];
CGRect-whiteRect=CGRectInset(bgView.bounds,10,5);
UIView*innerView=[[UIView alloc]initWithFrame:whiteRect];
innerView.autoresizingMask=UIViewAutoresizingFlexibleHeight;
innerView.backgroundColor=[UIColor whiteColor];
[bgView addSubview:innerView];
bgView.backgroundColor=[UIColor colorWithRed:225.0/255 green:224.0/255 blue:230.0/255 alpha:1.0];
self.backgroundView=bgView;
}
回归自我;
}
您也可以在此处添加self.selectedBackgroundView=selectedView,方法与在单元格高亮显示/选中时将特定视图分配给单元格相同


使用表视图的
contentInsets
属性。但不确定是否可以在故事板中设置。如果您有一个公开指示器(如我所做的),这将不起作用,因为它是
UITableViewCell
的一部分,而不是
UIView
@Sebastian您可以在UIView上设置带有公开指示器图像的imageView