繁体   English   中英

如何在UITableView上添加边距以插入内容

[英]How to add Margins on UITableView to inset content

我有一个表格视图,我想包含边距,以便表格的内容在左右两侧以及单元格之间都有一定的呼吸空间。

在此处输入图片说明

我设法做一个表视图,像:

表格检视

我的情节提要设计如下:

故事板

我所做的是在主视图中添加了UITableView ,并留出了10个边距。我添加了如图所示的约束。 Seperator style更改为None

然后,我添加了两个UITableViewCell

  1. 用于保存具有自定义行高70.0的数据
  2. 具有parentView相同背景的行,自定义行高为10.0

并实现了如下方法:

// Row count (Twice as needed, for showing the insect)
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 15*2;
}

// Returns cell based on indexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = nil;

    // Decides whether content or inset
    if (indexPath.row%2)
    {
        cell = [tableView dequeueReusableCellWithIdentifier:@"ReuseInset"];
    }
    else
    {
        cell = [tableView dequeueReusableCellWithIdentifier:@"ReuseMe"];
        cell.textLabel.text = @"MMP";
    }

    return cell;
}

// Returns custom row height based on indexpath
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{    if (indexPath.row%2)
    {
        return 10.0;
    }
    return 70.0;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM