I am trying to make my UITableViewCell something like this:
I decide to add an UIView to contain my text so that I can make the border. This is my .xib config
My ViewController's TableView setup
tableView.delegate = self
tableView.dataSource = self
self.tableView.rowHeight = UITableView.automaticDimension
self.tableView.estimatedRowHeight = 100
if #available(iOS 15.0, *) {
tableView.sectionHeaderTopPadding = 0.0
}
self.tableView.isScrollEnabled = false
But things end up like this
Is it something about my constraints setup? Or I am missing something, can someone point it out? Thanks in advance
You're missing a constraint between one of these two labels and the border view, which will make the height of the cell dynamic. These two labels are also center Y so you can make any of them have a bottom constraint with BorderView
, i.e., I will do it with AmountTypeLabel
and change the constraint bottom value to 10.
This is the output:
Just simple thinking about constraint from top to bottom with all subviews will make the cell have dynamic height:
ContentViewTop
|
BorderViewTop
|
Label
|
BorderViewBottom
|
ContentViewBottom