Forum Xamarin.iOS
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How to auto layout UIView inside UIView ?

PreranaPPreranaP USUniversity
edited December 2015 in Xamarin.iOS

Hi,

I am using auto layouts for the first time and trying to display an overlay(which contains tableview) on top of a view, following is the hierarchy of my overlay view :

View(MainView)
-View(SubView)
        -View(inside SubView)
        -UILabel(inside 2nd SubView)
        -UITableView( inside 2nd SubView)
        -UIButton(inside 2nd SubView)

I have enabled the AutoLayout and Size classes and set all view's constraints to 'Reset to suggested constraints', the issue is ,the 2nd subview is not getting autosized. The tableview gets clipped and UILabel and UIButton does not get displayed on the subview.

Is there any special considerations to be taken into account while setting auto layouts for views inside views, something I am missing ?


Any help or pointers will really be appreciated! Thanks a ton in advance.


-Prerana

Tagged:

Answers

  • adamkempadamkemp USInsider, Developer Group Leader mod

    What kind of constraints do you have on the view that you say isn't getting sized?

  • PreranaPPreranaP USUniversity

    Thanks @adamkemp for the response, following are the constraints on the '2nd SubView' which is not getting resized:


    Sibling and Ancestor Constraints


    -Leading Space to: Superview

    Equals : 102

    -Top Space to : Superview

    Equals : 125

    -Align Center X to : Superview

    -Align Center Y to : Superview

    Descendant Constraints


    -Leading Space to : UILabel

    Equals : 155

    -Top Space to : UILabel

    Equals : 33

    -Align X to : UIButton

    -Trailing margin Space Table View

    -Leading space to Table View

    -Top space to UIButton(2nd)

    The size of the 2nd SubView is (397 x 350). These are automatically set when using the 'Reset to Suggested Constraints' option, I have not changed any of it.

  • adamkempadamkemp USInsider, Developer Group Leader mod

    I don't see how you have constrained the size of the view that you're saying is not sizing right. Maybe I'm missing something. Could you try to reconstruct this view hierarchy and these constraints in a small example project and attach it here so I can take a look at the actual constraints in context?

  • PreranaPPreranaP USUniversity

    Sure I will attach a small project reproducing the issue. Thanks for the help :)

  • PreranaPPreranaP USUniversity

    Hi @adamkemp , Sorry for delay in response. Due to company's restrictions I was unable to upload a test project but I took it from your comment regarding the sizes constraints , did R&D on it further and got it resolved! I was not adding the size constraints by using the Pin option. It works fine now, the constraints are as follows :


    Sibling and Ancestor Contraints

    -Align Centre X to SuperView

    -Align Centre Y to SuperView

    -Width Equals 312
    -Height Equals 253


    Descendant Constraints

    -Align Centre X to View

    -Align Centre X to TableView

    -Align Centre X to UILabel

    -Align Centre Y to View

    Equals : 85

    -Align Centre Y to TableView

    Slowly slowly getting the grip over the AutoLayouts and they are not that bad at all ;) Thanks again, happy Coding :)

  • adamkempadamkemp USInsider, Developer Group Leader mod

    For future discussions, I highly doubt that your company policy would prohibit you from creating a from-scratch project with a proof-of-concept (written from scratch) that demonstrates the problem you're having. I wasn't asking for your real code. I was asking for a similar example that demonstrates the same problem. Any company that won't allow you to do that is a company you should probably run away from... :)

  • PreranaPPreranaP USUniversity
    edited December 2015

    Hmmmm, actually it was more of the firewall restrictions which did not let me upload anything online. Got it resolved after explaining the scenario,it wont be the issue henceforth. Thanks again for your time, I truly appreciate it :)

Sign In or Register to comment.