Forum Xamarin Xamarin.iOS

Ongoing iOS Custom Control issues - how to constrain the overall height?

DaveCarsonDaveCarson GBUniversity ✭✭✭

I'm slowly battling through the creation of a custom control for iOS but am having issues sizing the control itself.

I needed a 'header' type control - containing summary information about a person (Name, date of Birth, Age, Avatar etc). All this is working fine - even binding with MVVM Cross :-)

The problem is that when I drop it onto the parent view (I'm using nibs not storyboards) and size it up it looks "fine" but when I run the app onto the simulator it is clear that the control is not being constrained as I've specified.

To highlight this I've added a screenshot and the sample code that created it.

In the screenshot you will see Xamarin Studio in the background with the custom control on the right and the parent view on the left (with the custom control selected). I want the purple area to be displayed as the control - i.e. this is the extent of the content I want to display. I have applied a light grey colour to the base UIView to highlight it's position and as you will see it is present on the parent view.

Now - in the sample code I've attempted to define the size of the control by overriding IntrinsicContentSize but this has little effect (I think that the Auto Layout & Constraints does detect it though as it seems to know what height the control should be).

So (finally) how do I define the extents of the control surface?

Thanks in advance

Best Answer


  • DannyCDannyC US ✭✭✭✭

    @DaveCarson so you want the purple control to cover the whole gray area?

  • DaveCarsonDaveCarson GBUniversity ✭✭✭

    No, the purple area should be the extent of the control. The gray area isn't needed at all.

  • DaveCarsonDaveCarson GBUniversity ✭✭✭

    To clarify - the grey section of the control is the UIView that was added when I created the xib file. I didn't add it and don't need it.

  • DannyCDannyC US ✭✭✭✭

    @DaveCarson glad you found a solution. :smile:

Sign In or Register to comment.