我想让表格单元格中的所有内容垂直居中对齐。
我希望我的内容呈现在红线处
我试过了
通过代码
func updateTableViewContentInset() {
let viewHeight: CGFloat = view.frame.size.height
let tableViewContentHeight: CGFloat = placesTable.contentSize.height
let marginHeight: CGFloat = (viewHeight - tableViewContentHeight) / 2.0
self.placesTable.contentInset = UIEdgeInsets(top: marginHeight, left: 0, bottom: -marginHeight, right: 0)
}
override func viewWillAppear(_ animated: Bool) {
updateTableViewContentInset()
}
我试过了
我得到了
结果
甚至通过 Storyboard,但还没有得到我正在寻找的预期结果。
对我有什么提示吗?
最佳答案
您需要删除标签的顶部约束并从最左侧的标签按住 ctrl 拖动到 contentView 并选择垂直居中,但请注意您需要实现 heightForRowAt
以提供正确的高度
关于swift - 如何垂直对齐 Table View Cell 的所有内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53104506/