0

I have a UIView which consists of many dynamic sub views including UIStackView.

I have to add this UIView as my tableFooter, so I need to calculate it’s height. I tried calculated the height with two methods below, but I got incorrect size and zero.

//got incorrect size
let targetSize = CGSize(width: 300, height: UIView.layoutFittingCompressedSize.height)
let prefSizs = footerView.systemLayoutSizeFitting(targetSize)
footer.frame = CGRect(x: 0, y: 0, width 300, height: prefSize.height)

//got zero frame
let frame = footerView.frame

Is there anyway I can find the correct height for my dynamic UIView based on the given width?

Steven-Carrot
  • 2,368
  • 2
  • 12
  • 37
  • Have you tried sizeThatFits - https://developer.apple.com/documentation/uikit/uiview/1622625-sizethatfits ? – ftp27 Apr 27 '23 at 22:47
  • See https://stackoverflow.com/questions/28079591/using-autolayout-in-a-tableheaderview for likely solutions (it focuses on a table header but equally applies to table footer). – HangarRash Apr 27 '23 at 22:54
  • Ive been trying a few days with the above solutions, but still not work. I don’t know why the calculated height is still not correct. When measure the frame manually it’s 897, but I always got something around 500 with these solutions. – Steven-Carrot May 01 '23 at 07:44
  • @Steven-Carrot - it sounds like you do not have constraints configured correctly in your "footer view" ... can you show us that code - or, minimal but representative code? – DonMag May 02 '23 at 15:43

0 Answers0