I have a UITableViewHeader
which contains a UILabel
(dynamic height - can be one line or mulitple lines) and a custom UICollectionView
which shows a UILabel in each UICollectionViewCell
. Depending on which device is used, these UICollectionViewCells
can span over one line or they can be on two or three lines. That all doesn't matter that much.
My problem is in the heightForHeaderInSection
method. As this gets called before the frame is set (print(headerView.frame.height)
returns 0.0), I can't properly return the correct height. I am trying to access the headerView.frame.height so it can be set dynamically, but I fail to do so. I have looked into viewDidLayoutSubviews
, but then I would have to store it as a CGFloat
and force heightForHeaderInSection
to be called again.
I am pretty sure there must be a way to do this more easily. I also tried looking in to UITableView.automaticDimension
, but this hasn't brought me to the resolution either. Any suggestions?