prbaron
prbaron

Reputation: 867

Container views set height depending on children

Here is my problem. I have this storyboard : storyboard The first container must have a fixed height. It is related to the DetailFormViewController with the switch. I do not want it to be scrollable.

The second container must have a dynamic height, i.e. take the available height. It will show uitableview.

Here what I have on iPhone 6 : iphone 6 and on iPhone 5S : iphone 5S.

I have 3 questions :

  1. Why is there a blank space at the top of the DetailFormViewController tableView ?
  2. How can I remove it and I can I achieve my goal ?
  3. Do you think that the layout I put is the best way to achieve what I want (based on the iPhone 6 screenshot) ?

Thank you for all your answers.

Upvotes: 1

Views: 1530

Answers (2)

Shanmugaraja G
Shanmugaraja G

Reputation: 2778

For making the top container height to be fixed and the bottom container to be flexible. To keep only 4 rows in top container, set the top container height constraint value as equal to 4cells height(4 * cell height).

You need to add constraints on two containers as like follows:

I have named first container as Top Container View and 2nd container as Bottom Container View.

  Top Container View constraints:
     - Top Space to Top Layout Guide
     - Leading Space to container
     - Trailing Space to container
     - Vertical Space to Bottom Container View
     - Height

  Bottom Container View constraints:
     - Bottom Space to Bottom Layout Guide
     - Leading Space to container
     - Trailing Space to container

Constraints are mentioned in this figure: Constraints on Container views

Setting the height of the Top Container View defines that the top view height is fixed and the Bottom Container View's height becomes flexible.

iPhone 4s Portrait:

iPhone 4S Portrait Layout with above set constraints

iPhone 4S Landscape: iPhone 4S Landscape layout with same constraints

iPhone 5S Portrait:

iPhone 5S Portrait layout with same constraints

iPhone 5S Landscape: iPhone 5S Landscape layout with same constraints

Upvotes: 2

Mark McCorkle
Mark McCorkle

Reputation: 9414

More than likely you have Adjust Scroll View Insets enabled in your view controller.

enter image description here

Upvotes: 0

Related Questions