Forum Xamarin.iOS

Subviews with dynamic height

MarthughieMarthughie GBMember ✭✭
edited December 2015 in Xamarin.iOS

I am familiar with specifying constraints to organise the fixed layout of sub views with a view (using View.AddConstraints).

However what I would like to do is to have a stack of 4 subviews placed from top to bottom, the same width as main View, but so that the height of each changes depending on what is being contained. For example a subview might be used to hold a single UILabel in some cases, and in other cases (say) 5 UILabels. But the subview needs to be just tall enough to show everything is has.

Another example might be where a subview is being used to hold a UITableList, and the height of the subview needs to accommodate the number of rows which are populated in that TableList and no more.

If I use View.AddConstraints and do not specify a Height, but attach the Top of one subview to the bottom of the one above it, all subviews have 0 Height and are not shown, even if they have controls (e.g. labels) constrained within them.

Note that one consequence of this design is that I am expecting the display to be taller than the device and the user will have to scroll down to see all the subviews.

What the best way to autosize a subview to accommodate whatever is being contained within ?




  • MarthughieMarthughie GBMember ✭✭

    I resolved this in the end by populating all controls ahead of the ViewDidLoad event which made it possible to calculate heights.

Sign In or Register to comment.