我知道如何设置标题文本并设置样式,但对于我的生活,我找不到任何解释如何调整文本缩进的内容。这就是我试过的:
for i in range(len(primes) - 1):
if primes[i] - primes[i + 1] == g:
r.append(primes[i - 1])
r.append(primes[i])
result.append(r[0])
result.append(r[1])
上面的代码(以及我尝试的每个变体)都会导致错误:
无法激活约束,因为它们没有共同的祖先。
这导致我对我的电脑说,“如果func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int){
let header = view as! UITableViewHeaderFooterView
header.textLabel?.translatesAutoresizingMaskIntoConstraints = false
header.textLabel?.leftAnchor.constraint(equalTo: header.leftAnchor, constant: 15).isActive = true
}
让我到header.textLabel
,UILabel
确实是header
,我估计你应该知道一个人是另一个人的祖先!“
答案 0 :(得分:5)
您可以首先为整个separatorInset
设置TableView
,如下所示:
let headerInset: CGFloat = 50
tableView.separatorInset = UIEdgeInsets.init(top: 0, left: headerInset, bottom: 0, right: 0)
然后,如果您想将表格的单元格放置在TableView
边缘的阵容中,您可以使用forRowAt indexPath
方法执行此操作:
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.separatorInset = UIEdgeInsets.zero
}