How to change height of grouped UITableView header?

前端 未结 10 689
野性不改
野性不改 2020-12-07 09:22

I know how to change the height of the section headers in the table view. But I am unable to find any solution to change the default spacing before the first section.

10条回答
  •  借酒劲吻你
    2020-12-07 10:07

    If you use tableView style grouped, tableView automatically set top and bottom insets. To avoid them and avoid internal insets setting, use delegate methods for header and footer. Never return 0.0 but CGFLOAT_MIN.

    Objective-C

    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
        // Removes extra padding in Grouped style
        return CGFLOAT_MIN;
    }
    
    - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
        // Removes extra padding in Grouped style
        return CGFLOAT_MIN;
    }
    

    Swift

    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        // Removes extra padding in Grouped style
        return CGFloat.leastNormalMagnitude
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        // Removes extra padding in Grouped style
        return CGFloat.leastNormalMagnitude
    }
    

提交回复
热议问题