如何在GROUPED UITableView中更改BETWEEN部分的高度?

理想评*_*论学派 14 iphone ios

默认高度对我来说太大了.如何更改两个部分之间的高度?

================================================== ==========================

抱歉我的英语不好......我的意思是两个部分之间的差距太大了.怎么改呢?

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    CGRect frame = CGRectMake(0, 0, tableView.frame.size.width, 2.0f);
    UIView *view = [[[UIView alloc] initWithFrame:frame] autorelease];
    view.backgroundColor = [UIColor blueColor];
    return view;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    CGRect frame = CGRectMake(0, 0, tableView.frame.size.width, 2.0f);
    UIView *view = [[[UIView alloc] initWithFrame:frame] autorelease];
    view.backgroundColor = [UIColor redColor];
    return view;
}
Run Code Online (Sandbox Code Playgroud)

我更改了每个部分的页眉视图和页脚视图.这是结果: 在此输入图像描述

我认为可能有一个最小高度的间隙,因为我将页眉和页脚的高度设置为2px,但两个部分之间的差距仍然很大.

Jam*_*ord 16

您可以在每个部分之间使用页脚视图,并通过在UITableView的委托中实现以下方法为它们提供所需空间的大小.

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

在第一个委托方法中,您可以返回一个简单的UIView实例,在第二个方法中,您可以返回该视图应该的高度.第二个委托方法应该允许您控制部分之间的差距.

  • 如果你想使高度为零,记住不要返回0但是要略大于0的值,比如说0.000001f (3认同)

roc*_*ift 8

在 iOS 15 上,您可以更改节标题顶部填充

if #available(iOS 15.0, *) {
    tableView.sectionHeaderTopPadding = 0
}
Run Code Online (Sandbox Code Playgroud)