swift - 如何垂直对齐 Table View Cell 的所有内容?

标签 swift uitableview tableview uistoryboard tablecellrenderer

我想让表格单元格中的所有内容垂直居中对齐。

enter image description here

我希望我的内容呈现在红线处

enter image description here


我试过了

通过代码

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()
}

enter image description here


我试过了

enter image description here

我得到了

enter image description here

结果

enter image description here

甚至通过 Storyboard,但还没有得到我正在寻找的预期结果。

对我有什么提示吗?

最佳答案

您需要删除标签的顶部约束并从最左侧的标签按住 ctrl 拖动到 contentView 并选择垂直居中,但请注意您需要实现 heightForRowAt 以提供正确的高度

关于swift - 如何垂直对齐 Table View Cell 的所有内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53104506/

相关文章:

iphone - Storyboard的 UITableview 中未调用 initWithStyle

ios - 单击屏幕后,表格 View 内容才会出现

objective-c - for 循环在editingStyleForRowAtIndexPath 中仅执行一次

ios - Swift - 如何检查 TableView 是否为空

swift - 将 SecKey 保存和读取到钥匙串(keychain)

ios - 'PusherSwift' 验证未在 swift 中调用

ios - tableview自定义单元格注册失败

iphone - 一个部分中的一个部分 - UITableView -

ios - 相同的 View Controller 加载两次

swift - UIStackView 在 tableView Cell didSet 中添加排列 subview