美文网首页
UITableViewStyleGrouped模式下烦人的多余间

UITableViewStyleGrouped模式下烦人的多余间

作者: 超级卡布达 | 来源:发表于2018-12-05 14:26 被阅读18次

第一种方法:通过代理设置head和foot的高度

    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let view = UIView(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: 20))
        view.backgroundColor = UIColor.gray
        return view
    }
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        return nil
    }
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 20
    }
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        if section == 3 {
            return 50
        }
        return 0.01
    }

注意:只设置高度是没效果的

    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 20
    }
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        if section == 3 {
            return 50
        }
        return 0.01
    }

第二种方法:直接设置 无需设置代理

        tableView.sectionFooterHeight = 0;
        tableView.sectionHeaderHeight = 10;

如果同时也设置代理,那将会以代理的高度为标准

相关文章

网友评论

      本文标题:UITableViewStyleGrouped模式下烦人的多余间

      本文链接:https://www.haomeiwen.com/subject/vyoicqtx.html