ios - Constrain width of UIStackView arranged views inside UIScrollView -


i have embedded uistackview inside uiscrollview. when add view arranged subview uistackview, width expands beyond frame , causes horizontal scrollbar appear, when add horizontal width layout constraints. i not want uiscrollview expand horizontally.

the code programatically creating uistackview inside uiscrollview in viewdidload:

_scrollview = [uiscrollview new]; _scrollview.delegate = self; _scrollview.translatesautoresizingmaskintoconstraints = no; _scrollview.pagingenabled = yes; [self.view addsubview:_scrollview]; [self.view addconstraints:[nslayoutconstraint constraintswithvisualformat:@"h:|[scrollview]|" options:nslayoutformatalignallcenterx metrics:nil views:@{@"scrollview": _scrollview}]]; [self.view addconstraints:[nslayoutconstraint constraintswithvisualformat:@"v:|[scrollview]|" options:nslayoutformatalignallcenterx metrics:nil views:@{@"scrollview": _scrollview}]];  // configure stackview _stackview = [uistackview new]; _stackview.translatesautoresizingmaskintoconstraints = no; _stackview.axis = uilayoutconstraintaxisvertical; [_scrollview addsubview:_stackview]; [_scrollview addconstraints:[nslayoutconstraint constraintswithvisualformat:@"h:|[stackview]|" options:nslayoutformatalignallcenterx metrics:nil views:@{@"stackview": _stackview}]]; [_scrollview addconstraints:[nslayoutconstraint constraintswithvisualformat:@"v:|[stackview]|" options:nslayoutformatalignallcenterx metrics:nil views:@{@"stackview": _stackview}]]; 

then add custom view, , autolayout constraint limit subview's width stackview's:

customview *customview = [customview loadfromxib]; // helper load xib [_stackview addarrangedsubview:customview]; [_stackview addconstraints:[nslayoutconstraint constraintswithvisualformat:@"h:|[customview]|" options:nslayoutformatdirectionleadingtotrailing metrics:nil views:@{@"customview": customview}]]; 

however, resulting customview double width of frame. none of ib-set constraints in customview have fixed widths, expect content resize fit frame. doing wrong?


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -