How to avoid UILabel to increase height on this scenario?

I have the following control hierarchy

Scroll View
|__ Content View
    |__ View  (fix height)
    |__ Label (variable content)
    |__ Table (fix height)
    |__ View  (only an anchor for scroll view, no other usage)

Last view is only there to force the scroll actually scroll when necessary (setting bottom space to container to 0 on this view). Without any control setting distance to bottom, I see no scroll.

I have height constrains over 1st view and Table. My problem is that when sum of all heights < screen height, it increases the size of the label to honor last view constraint of bottom space = 0.

I don't want the label to increase the size but the latest view. I tried everything

  • Set a height constraint over the last view with a "greater or equal" condition
  • Call sizeToFit on the label everywhere to force it to reduce the size
  • Etc

Nothing worked, I still see the label taking more space than required.

How to avoid label to avoid taking more space than necessary while still honoring the bottom distance to 0 for the view. I'm willing to remove the latest view if there is other way to force scroll view to actually show scroll bar when necesary.

Answers


Click on your label in IB, then click on the size inspector pane, find the horizontal and vertical content hugging priority and increase both. It is low by default you probably want it on high to prevent the layout engine from increasing its size and instead "hug" its intrinsic size.


Need Your Help

Avoid create session in Spring

java spring security session controller

I have a Spring web application that creates a session on each request, and I want to avoid this.