#StackBounty: #swift #xcode #uitableview #storyboard Resize table header when using dynamic types

Bounty: 50

I have a TableViewController with a header.
This header is a container, which links to another storyboard named Header.storyboard

TableViewController

Header.storyboard contains a stack view with some labels, that are dynamically typed.

Labels text comes from DB.

No regards to the text dimension or size I want to visualise it correctly.

enter image description here

I’ve used some answers from SO to get the header correctly resize, but without luck:

import UIKit

class TableViewController: UITableViewController {

    @IBOutlet weak var tableHeaderView: UIView!

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()

        // Dynamic sizing for the header view
        if let headerView = tableHeaderView {
            headerView.setNeedsLayout()
            headerView.layoutIfNeeded()

            let height = headerView.systemLayoutSizeFitting(UILayoutFittingCompressedSize).height
            var headerFrame = headerView.frame

            // If we don't have this check, viewDidLayoutSubviews() will get
            // repeatedly, causing the app to hang.
            if height != headerFrame.size.height {
                headerFrame.size.height = height
                headerView.frame = headerFrame
                tableHeaderView = headerView
           }
       }
   }
}


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.