【发布时间】:2012-10-01 12:22:34
【问题描述】:
我有一个带有一个节标题的分组表视图。如何在节标题和第一个 tableview 单元格之间创建一个空格?
【问题讨论】:
-
增加section header高度并相应设置viewForHeaderInSection中的视图。
标签: ios uitableview
我有一个带有一个节标题的分组表视图。如何在节标题和第一个 tableview 单元格之间创建一个空格?
【问题讨论】:
标签: ios uitableview
你可以这样做
tableView:heightForHeaderInSection:(NSInteger)section
改变高度
如果(部分 ==0)
返回 7; //(标题和第一行之间的空间);
别的 返回 6;
【讨论】:
您不能在两者之间添加空格,但可以使标题高度更大,并使标题的内容不会一直到它的底部。
【讨论】:
[看起来像这样。]我以这种方式解决了,这实际上在单元格和标题之间创建了一种空间。希望对大家有所帮助。
(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;
} }
【讨论】:
override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 10.00001
}
【讨论】: