Joe*_*oel 46 layout uitableview ios swift
我需要减少两个部分之间的空间UITableView.我看了这个问题,但解决方案不允许我的自定义标题视图,因为它结合了页脚和标题的空间.
这是一张照片UITableView.黑色是UITableView背景颜色.

roc*_*ift 243
在 iOS 15 上,您可能想要减少sectionHeaderTopPadding
if #available(iOS 15.0, *) {
tableView.sectionHeaderTopPadding = 0
}
Run Code Online (Sandbox Code Playgroud)
Ica*_*aro 107
您是否尝试覆盖此功能:
override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return .leastNormalMagnitude
}
Run Code Online (Sandbox Code Playgroud)
Sud*_*vis 39
我认为您可以通过在页脚板或XIB中将页脚视图高度调整为min来解决此问题.
我不知道你在代码中写的页脚高度.对不起,如果我错了.
UITableView中隐藏页脚视图的可能重复项
Ali*_*ris 13
对于Swift 3
override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return CGFloat.leastNormalMagnitude
}
Run Code Online (Sandbox Code Playgroud)
Lad*_*d.c 13
对于 Swift 4+ 你需要实现这两个方法
extension MyViewController : UITableViewDelegate {
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return CGFloat.leastNormalMagnitude
}
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
return UIView()
}
}
Run Code Online (Sandbox Code Playgroud)
Fer*_*nas 10
对于 Swift 5+:
默认情况下,页眉和页脚有一些空间。这就是为什么我遇到了为各部分设置精确分隔的问题。
我对两个部分之间的分离的解决方案如下:
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
if section == 0 {
return 24
} else if section == 1 {
return 32
} else {
return 40
}
}
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
nil
}
override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
nil
}
override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
CGFloat.leastNormalMagnitude
}
Run Code Online (Sandbox Code Playgroud)
正如您在 viewForFooterInSection 和 viewForHeaderInSection 中看到的那样,我需要返回 nil。
如果您只想更改 footerHeight,只需为 heightForHeaderInSection 返回 CGFloat.leastNormalMagnitude,并返回 heightForFooterInSection 中每个部分的高度。
您需要使用方法heightForHeaderInSection来定义标题和单元格文本之间的空间.您也可以根据不同的部分进行更改,例如.在某些部分你可能需要显示更多的距离和一些,你不想显示差距.对于这种情况,您可以使用0.000001f的CGFLOAT_MIN.举个例子,如何使用不同的标题高度的不同部分
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (section == 0 || section == 2)
{
return 55.0;
}
else
{
return CGFLOAT_MIN;
}
}
Run Code Online (Sandbox Code Playgroud)
希望它会对你有所帮助.
小智 6
我只需减少表格视图部分标题的顶部填充:
tableView.sectionHeaderTopPadding = 0
Run Code Online (Sandbox Code Playgroud)
除了Icaro发布的答案外,我还想补充一点,您还需要实现要tableView:viewForFooterInSection:返回nil的部分的方法,以删除下面的空白部分,该方法将变为:
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 0.001f;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
return nil;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
53268 次 |
| 最近记录: |