【问题标题】:Create space between section header and cell在节标题和单元格之间创建空间
【发布时间】:2012-10-01 12:22:34
【问题描述】:

我有一个带有一个节标题的分组表视图。如何在节标题和第一个 tableview 单元格之间创建一个空格?

【问题讨论】:

  • 增加section header高度并相应设置viewForHeaderInSection中的视图。

标签: ios uitableview


【解决方案1】:

你可以这样做

tableView:heightForHeaderInSection:(NSInteger)section

改变高度

如果(部分 ==0)
返回 7; //(标题和第一行之间的空间);
别的 返回 6;

【讨论】:

    【解决方案2】:

    您不能在两者之间添加空格,但可以使标题高度更大,并使标题的内容不会一直到它的底部。

    【讨论】:

    • 是的,我最终就是这样做的。
    • 不用担心,我自己也做过。在 UICollectionView 中,它们具有用于单元格和行之间的间隔的属性等...:-D
    【解决方案3】:

    [看起来像这样。]我以这种方式解决了,这实际上在单元格和标题之间创建了一种空间。希望对大家有所帮助。

    • (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { if ([tableView.dataSource tableView:tableView numberOfRowsInSection:section] == 0) { 返回零; } 别的 { UIView *sectionHeaderView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, tableView.frame.size.width, 50.0)];

      sectionHeaderView.backgroundColor = [self colorWithHexString:@"2292a7"];
      
      UILabel *headerLabel = [[UILabel alloc] initWithFrame:
                              CGRectMake(0, 0, sectionHeaderView.frame.size.width, 35.0)];
      
      UILabel *headerLabel1 = [[UILabel alloc] initWithFrame:
                              CGRectMake(0, 35, sectionHeaderView.frame.size.width, 10.0)];
      
      headerLabel.backgroundColor = [UIColor clearColor];
      headerLabel.textAlignment = NSTextAlignmentCenter;
      [headerLabel setFont:[UIFont fontWithName:@"Helvetica Neue" size:16.0]];
      [headerLabel setTextColor:[UIColor whiteColor]];
      [sectionHeaderView addSubview:headerLabel];
      
      headerLabel1.backgroundColor = [UIColor grayColor];
      [sectionHeaderView addSubview:headerLabel1];
      
      if ([self.dateArray count] > 0)
      {
          headerLabel.text = [self.feedDateArray objectAtIndex:section];
      }
      
      return sectionHeaderView;
      

      } }

    【讨论】:

      【解决方案4】:
      override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
      return 10.00001
      

      }

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-07
        • 2023-04-10
        相关资源
        最近更新 更多