swift - Programmatic layout : UIStackView alignment doesn't seem to work -


i have created uiviewcontroller uistackview (vertical axis) wrapped in uiscrollview that's pinned edges of root view auto-layout constraints.

i have generated number of uibuttons , added arranged subviews of uistackview.

i have tried no avail centre align uibuttons in uistackview.

i'm not i'm doing wrong.

here's code:

import uikit  class viewcontroller: uiviewcontroller { var scrollview: uiscrollview! var stackview: uistackview!  override func viewdidload() {     super.viewdidload()      view.backgroundcolor = uicolor.whitecolor()      scrollview = uiscrollview()     scrollview.translatesautoresizingmaskintoconstraints = false     view.addsubview(scrollview)      view.addconstraints(nslayoutconstraint.constraintswithvisualformat("h:|[scrollview]|", options: .alignallcenterx, metrics: nil, views: ["scrollview": scrollview]))     view.addconstraints(nslayoutconstraint.constraintswithvisualformat("v:|[scrollview]|", options: .alignallcenterx, metrics: nil, views: ["scrollview": scrollview]))       stackview = uistackview()     stackview.translatesautoresizingmaskintoconstraints = false     stackview.axis = .vertical     stackview.alignment = .center     scrollview.addsubview(stackview)      scrollview.addconstraints(nslayoutconstraint.constraintswithvisualformat("h:|[stackview]|", options: nslayoutformatoptions.alignallcenterx, metrics: nil, views: ["stackview": stackview]))     scrollview.addconstraints(nslayoutconstraint.constraintswithvisualformat("v:|[stackview]|", options: nslayoutformatoptions.alignallcenterx, metrics: nil, views: ["stackview": stackview]))      _ in 1 ..< 100 {         let vw = uibutton(type: uibuttontype.system)         vw.settitle("button", forstate: .normal)         stackview.addarrangedsubview(vw)     } }  } 

an equal width constraint between scrollview , stackview needed. this:

scrollview.addconstraints(nslayoutconstraint.constraintswithvisualformat("h:[stackview(==scrollview)]", options: .alignallcenterx, metrics: nil, views: ["stackview": stackview, "scrollview": scrollview])) 

that did me.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -