美文网首页
UITableView 相关

UITableView 相关

作者: AntKing | 来源:发表于2020-02-28 11:53 被阅读0次

tableHeaderView 和 tableFooterView

  • UITableView属性里的tableHeaderView和tableFooterView是和UITableView一起滚动的,delegate方法里的是不会跟随一起滚动的
class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
   
    
    @objc dynamic private lazy var tableView: UITableView = {
        let view = UITableView(frame: CGRect.zero, style: UITableView.Style.plain)
        view.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
        return view
    }()

    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.tableView.dataSource = self
        self.tableView.delegate = self
        self.tableView.frame = self.view.bounds
        let tableHaderView = UIView()
        tableHaderView.frame = CGRect.init(x: 0, y: 0, width: 414, height: 50)
        tableHaderView.backgroundColor = UIColor.yellow
        self.tableView.tableHeaderView = tableHaderView
        
        let tableFooterView = UIView()
        tableFooterView.frame = CGRect.init(x: 0, y: 0, width: 414, height: 30)
        tableFooterView.backgroundColor = UIColor.black
        self.tableView.tableFooterView = tableFooterView
        
        self.view.addSubview(self.tableView)
        
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 40
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
        cell?.textLabel?.text = "\(indexPath.row)"
        return cell!
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let header = UIView()
        header.frame = CGRect.init(x: 0, y: 0, width: 414, height: 50)
        header.backgroundColor = UIColor.red
        return header
    }
    
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        let footer = UIView()
        footer.frame = CGRect.init(x: 0, y: 0, width: 414, height: 50)
        footer.backgroundColor = UIColor.green
        return footer
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 100
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 100
    }

}

相关文章

  • UITableView iOS8 侧滑删除

    刷新列表 UITableView 相关 UITableView 索引详细

  • iOS 优秀的第三方学习

    UITableView 相关 UITableView+FDTemplateLayoutCell 苹果官方开发文档 ...

  • UITableView相关

    关键词: 开发, iOS, tableView, 使用SnapKit+FDTemplateLayoutCell时c...

  • UITableView相关

    iOS开发之UITableView全面解析详细整理:UITableView优化技巧iOS 保持界面流畅的技巧

  • UITableView相关

    1、去掉UITableView上多余的分割线 设置UITableView的tableFooterView为fram...

  • UITableView 相关

    tableHeaderView 和 tableFooterView UITableView属性里的tableHe...

  • UITableView相关

    1、基础知识 样式 UITableView有两种样式(plain,grouped),其中plain为普通列表样式,...

  • UITableView相关

    group and plain style iOS的tableView有两种样式:一种是plain(默认);一种是...

  • UITableView 编辑模式详解

    UITableView 编辑模式详解 UITableView的相关编辑操作非常全,今天我们来做一个总结。跟编辑相关...

  • iOS 11 适配相关

    UItableview相关 手机更新到iOS 11 , UItableview出现cell间距扩大,头部偏移等情况...

网友评论

      本文标题:UITableView 相关

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