]我最近在方法的自定义视图上添加了标签,但是无法将其他视图添加并附加到我在uitable视图上的初始自定义视图。尚未能够使函数返回元组...,尝试过:
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let label = UILabel()
label.textColor = .darkGray
label.textAlignment = .center
label.text = "Zero Zilch Zippal"
label.font = UIFont(name: "AvenirNext-Medium", size: 30)
let label2 = UILabel()
label2.textColor = .darkGray
label2.textAlignment = .center
label2.text = "But it doesn't need to be..."
label2.font = UIFont(name: "AvenirNext-Medium", size: 38)
label.addSubview(label2)
label2.anchor(self.view.topAnchor, left:
self.view.leftAnchor, bottom: self.view.bottomAnchor, right:
self.view.rightAnchor, topConstant: 250, leftConstant: 0,
bottomConstant: 0, rightConstant: 0, widthConstant: 0, heightConstant:
0)
// let view = [label, label2]
return label
}
也尝试返回一个数组,但都没有对我有用...
func tableView(_ tableView: UITableView, viewForFooterInSection section: [Int]) -> UIView? {
let label = UILabel()
label.textColor = .darkGray
label.textAlignment = .center
label.text = "Zero Zilch Zippal"
label.font = UIFont(name: "AvenirNext-Medium", size: 30)
let label2 = UILabel()
label2.textColor = .darkGray
label2.textAlignment = .center
label2.text = "But it doesn't need to be..."
label2.font = UIFont(name: "AvenirNext-Medium", size: 38)
label.addSubview(label2)
label2.anchor(self.view.topAnchor, left:
self.view.leftAnchor, bottom: self.view.bottomAnchor, right:
self.view.rightAnchor, topConstant: 250, leftConstant: 0,
bottomConstant: 0, rightConstant: 0, widthConstant: 0, heightConstant:
0)
let view = [label, label2]
return view
}
答案 0 :(得分:0)
我设法做到了:
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let result = resultView
// recreate insets from existing ones in the table view
let width = tableView.bounds.width
let sepFrame = CGRect(x: 0, y: 20, width: width, height: 1)
// create layer with separator, setting color
let sep = CALayer()
sep.frame = sepFrame
sep.backgroundColor = tableView.separatorColor?.cgColor
result?.layer.addSublayer(sep)
return result
}
尝试从一个视图开始。