Section Index Titles Cover UITableViewCell 视图

Section Index Titles Cover UITableViewCell View

我正在尝试以编程方式将堆栈视图添加到我的 UITableViewCell。

章节索引标题阻碍了视线。

这是我用来在 UITableViewCell 中嵌入堆栈视图的代码。

self.addSubview(mainStack)
mainStack.topAnchor.constraint(equalTo: self.safeAreaLayoutGuide.topAnchor, constant: self.TOP_PADDING).isActive = true
mainStack.bottomAnchor.constraint(equalTo: self.safeAreaLayoutGuide.bottomAnchor, constant: -self.BOTTOM_PADDING).isActive = true
mainStack.leadingAnchor.constraint(equalTo: self.safeAreaLayoutGuide.leadingAnchor, constant: self.SIDE_PADDING).isActive = true
mainStack.trailingAnchor.constraint(equalTo: self.safeAreaLayoutGuide.trailingAnchor, constant: 0).isActive = true

如何在不依赖固定常量(即一些固定填充)的情况下修复视图障碍?

改变

mainStack.trailingAnchor.constraint(equalTo: self.safeAreaLayoutGuide.trailingAnchor, constant: 0).isActive = true

mainStack.trailingAnchor.constraint(equalTo: self.contentView.safeAreaLayoutGuide.trailingAnchor, constant: 0).isActive = true

结果: