默认高度对我来说太大了.如何更改两个部分之间的高度?
================================================== ==========================
抱歉我的英语不好......我的意思是两个部分之间的差距太大了.怎么改呢?
- (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实例,在第二个方法中,您可以返回该视图应该的高度.第二个委托方法应该允许您控制部分之间的差距.
在 iOS 15 上,您可以更改节标题顶部填充
if #available(iOS 15.0, *) {
tableView.sectionHeaderTopPadding = 0
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17319 次 |
| 最近记录: |