我正在尝试设置约束。我遇到一个问题,即我创建的程序化视图之前要加载tableview故事板出口。因此,我无法设置介于两者之间的约束。这是我的限制...
func tableviewsConstraints(){
//Label
todaysdeadlineLabel = UILabel()
todaysdeadlineLabel.translatesAutoresizingMaskIntoConstraints = false
todaysdeadlineLabel.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: 20).isActive = true
todaysdeadlineLabel.trailingAnchor.constraint(equalTo: self.view.trailingAnchor, constant: -20).isActive = true
todaysdeadlineLabel.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 20).isActive = true
todaysdeadlineLabel.heightAnchor.constraint(equalToConstant: 30).isActive = true
todaysdeadlineLabel.text = "Today's Deadlines"
self.view.addSubview(todaysdeadlineLabel)
homeTableView.translatesAutoresizingMaskIntoConstraints = false
homeTableView.layer.cornerRadius = 10
homeTableView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: 20).isActive = true
homeTableView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor, constant: -20).isActive = true
homeTableView.topAnchor.constraint(equalTo: self.todaysdeadlineLabel.topAnchor, constant: 120).isActive = true
homeTableView.heightAnchor.constraint(equalToConstant: homeTableView.rowHeight * 3).isActive = true
}
override func viewDidLoad() {
super.viewDidLoad()
tableviewsConstraints()
表视图正在被添加到我认为标签之前的视图。