0

I have a xib file with a UIView that I want to use as a tableViewHeaderView. The view has a label with a bunch of text. No matter what I try I cannot get it to adjust so the height fits in correctly according to the constraints.

This is the nib:enter image description here

The label is set to adjust its height to fit the text and all the margins are 15 points away from the superview. However when this is added to the table view it looks like this:

enter image description here

I can't seem to figure out what I'm missing, here is the sample project, is there some way you are supposed to setup the nib to allow the view to be sized by its contents constraints?

Edit: I've tried the answer given here with no luck: https://stackoverflow.com/a/21099430/383603

Edit 2: It should look like this:

enter image description here

Community
  • 1
  • 1
Steve
  • 2,526
  • 2
  • 20
  • 30

1 Answers1

0

It looks like that for the tableViewHeaderView view, the actually height is taken from the xib file, which is 570 in your case. If that is true the auto layout system should get an unambiguous state:

  • vertical hugging priority is 1000 which is the highest and in order to get that working
  • it needs to break the 15 top or 15 bottom point constraint
  • or resize your header dynamically

Based on how your pictures look like, it's most likely that the runtime system decided to break the vertical hugging priority to keep everything else valid

Possible solutions might be:

  • Change the height of the header dynamically
  • Change (lower) the priority of top and/or bottom constraint