I want the UIStackView to resize to fit their subviews (UIImageView and UILabel in this case)
let headerView = UIStackView()
headerView.axis = .vertical
headerView.alignment = .center
headerView.distribution = .equalSpacing
headerView.spacing = 10
let headerImage = UIImageView(...)
headerImage.contentMode = .scaleAspectFill
headerImage.clipsToBounds = true
headerImage.frame = CGRect(x: 0, y: 0, width: tableView.frame.width, height: tableView.frame.width / 1.618)
let desciptionView = UILabel()
desciptionView.text = "Some very long text wrapping multiple lines..."
desciptionView.numberOfLines = 0
desciptionView.font = UIFont.preferredFont(forTextStyle: UIFontTextStyle.body)
headerView.addArrangedSubview(headerImage)
headerView.addArrangedSubview(desciptionView)
print(headerView.bounds) // always 0,0,0,0
print(headerView.frame) // always 0,0,0,0
tableView.tableHeaderView = headerView
(in this code height and width are 0)
How to implement the wanted behaviour?