tableview Group的使用-section Header的高度显示一致

来源:互联网 发布:大数据 服务型政府 编辑:程序博客网 时间:2024/06/13 08:51

func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {        if section == 0 {            return 20        }        return 20    }    func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {        //        var header : UIView! = UIView()        var header : UILabel! = UILabel()        header.text = "\(section)"        header.textAlignment = NSTextAlignment.Center        header.frame = CGRectMake(0, 0, CGRectGetWidth(tableView.bounds), 1)        return header    }    /// 注意这下面的两句话才能真正的让header的高度一致    func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {        var header : UIView! = UIView()        header.frame = CGRectMake(0, 0, CGRectGetWidth(tableView.bounds), 1)        return header    }    func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {        return 1    }

如果去掉下面两个方法显示的高度就不一样了。

附简单Demo

0 0
原创粉丝点击