update the header's frame and set it again set the tableHeaderView so that the required height can be determined This text is set at runtime and might be short or long." = is a message with enough text to span multiple lines. That height can then be applied to the header, and the header is set a second time to reflect the change. In summary, I add the header once and use it to find the required height. I asked and answered a similar question here. I don't know if I have to set some constraints directly on the CustomView, I think the height of the CustomView is determined by the constraints on the UILabel "title" in it.ĮDIT 2: After another investigation it seems the height and width of the CustomView are correctly calculated, but the top of the CustomView is still at the same level than the top of the UITableView and they move together when I scroll. _tableView.tableHeaderView = _detailsView ]]] // These 4 constraints make the UITableView stays 0 away from the superview top left right and bottom. _anslatesAutoresizingMaskIntoConstraints = NO I'm using a handy library 'KeepLayout' because writing constraints manually takes forever and way too many line for one single constraint but the methods are self-explaining.Īnd the UITableView has these constraints : _tableView = init]
]]] // title has to stay at least 5 away from the supperview Top The CustomView' subview that I'm using has these constraints : _title = init] My question : is it possible at all to accomplish this without setting the frame manually ? It seems that no matter what I do, the height of the UITableView' tableHeaderView is always 0 (so is the width, x and y). I made a subclass of UIView added everything (labels etc.) I wanted with their constraints, then I added this CustomView to the UITableView' tableHeaderView.Įverything works just fine except the UITableView always displays above the CustomView, by above I mean the CustomView is under the UITableView so it can't be seen !
Since I discovered AutoLayout I use it everywhere, now I'm trying to use it with a tableHeaderView.