创建一个涵盖整个tableview的时间轴视图

时间:2017-07-01 10:02:58

标签: swift tableviewcell

我创建了一个表视图控制器,它具有一个时间轴视图,该视图以包含内容的单元格结尾。 enter image description here 从图中可以看出,tableview的垂直线在tableview的第二行结束,因为它从数组中拉出两个列表,但是我想显示直到底部的垂直线和圆圈中的圆圈。未使用的表视图单元格我以编程方式创建了视图。自定义表格视图单元格如

private func setUpTimeline(){

        addSubview(bezierLine)

        bezierLine.leftAnchor.constraint(equalTo: self.leftAnchor, constant: 92.5).isActive = true
        bezierLine.topAnchor.constraint(equalTo: self.topAnchor).isActive = true
        bezierLine.widthAnchor.constraint(equalToConstant: 0.8).isActive = true
        bezierLine.bottomAnchor.constraint(equalTo: self.bottomAnchor).isActive = true


        addSubview(circularCompletion)

        circularCompletion.leftAnchor.constraint(equalTo: self.bezierLine.leftAnchor, constant: -12.5).isActive = true
        circularCompletion.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
        circularCompletion.widthAnchor.constraint(equalToConstant: 25).isActive = true
        circularCompletion.heightAnchor.constraint(equalToConstant: 25).isActive = true


        addSubview(timeLabel)
        timeLabel.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
        timeLabel.leftAnchor.constraint(equalTo: self.leftAnchor, constant: 8).isActive = true
        timeLabel.rightAnchor.constraint(equalTo: self.bezierLine.leftAnchor).isActive = true
        timeLabel.heightAnchor.constraint(equalToConstant: 30).isActive = true


        addSubview(surveyNameLabel)
        surveyNameLabel.leftAnchor.constraint(equalTo: self.bezierLine.rightAnchor, constant: 18).isActive = true
        surveyNameLabel.topAnchor.constraint(equalTo: self.circularCompletion.topAnchor).isActive = true
        surveyNameLabel.rightAnchor.constraint(equalTo: self.rightAnchor).isActive = true
        surveyNameLabel.heightAnchor.constraint(equalToConstant: 20).isActive = true

        addSubview(surveyDetailsLabel)
        surveyDetailsLabel.leftAnchor.constraint(equalTo: self.surveyNameLabel.leftAnchor).isActive = true
        surveyDetailsLabel.topAnchor.constraint(equalTo: self.surveyNameLabel.bottomAnchor, constant: 8).isActive = true
        surveyDetailsLabel.rightAnchor.constraint(equalTo: self.surveyNameLabel.rightAnchor).isActive = true
        surveyDetailsLabel.heightAnchor.constraint(equalToConstant: 15).isActive = true
    }

1 个答案:

答案 0 :(得分:0)

这实际上非常简单。我创建了一个从UIView扩展的类,并且符合Tableview数据源,委托。创建了这个块,

lazy var table: UITableView = {
        var bounds = UIScreen.main.bounds
        let tv = UITableView(frame:CGRect(x: 0, y: 0, width: bounds.width, height: 800))
        tv.backgroundColor = UIColor.red
        tv.separatorColor = UIColor.clear
        tv.dataSource = self
        tv.delegate = self
        return tv
    }()

然后注册了自定义单元格

override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(table)

        table.register(EmptyTableViewCells.self, forCellReuseIdentifier: cellId)
    }

在主视图控制器中,我创建了一个名为" surveyFooter"的类的实例。并将其添加到tableFooterView。

self.tableView.tableFooterView = surveyFooter