Search code examples
swiftuitableviewtableviewuistoryboardtablecellrenderer

How can I vertically align all my contents of my Table View Cell?


I want to make all the contents in my table cell vertical align center.

enter image description here

I want my content to render at the red line

enter image description here


I've tried

via code

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


I tried

enter image description here

I got

enter image description here

result

enter image description here

or even via the storyboard, but have not get the desired result that I am looking for yet.

Any hints for me ?


Solution

  • Firstly select the two elements in left and add them in vertical stack view like this: enter image description here

    Then select the elements that you want to center inside your cell and apply Vertically in container.

    enter image description here

    For horizontal constraints between elements, select each element and add constraints like this:

    enter image description here