ios - Auto Layout: layoutMarginsGuide -
how rewrite visual format
addconstraints(nslayoutconstraint.constraintswithvisualformat("|-[label]-|", options: .alignallbaseline, metrics: nil, views: ["label": label])) addconstraints(nslayoutconstraint.constraintswithvisualformat("v:|-[label]-|", options: .alignallcenterx, metrics: nil, views: ["label": label])) by moving layout guides (with margins)?
i tried with
label.topanchor.constraintequaltoanchor(layoutmarginsguide.topanchor).active = true label.leftanchor.constraintequaltoanchor(layoutmarginsguide.leftanchor).active = true label.bottomanchor.constraintequaltoanchor(layoutmarginsguide.bottomanchor).active = true label.rightanchor.constraintequaltoanchor(layoutmarginsguide.rightanchor).active = true but not work. layoutmarginsguide.layoutframe not have expected value (yes call in layoutsubviews after super executed). constraints set, acts there 0 margin. layouts , gives expected layoutframe when layout margin set negative; not want obviously, demonstrates constraints set margins guides. looks i'm missing something...
it seems me layoutmarginsguide not ready in init method of uiview. i'm getting similar issues, setting constraints in updateconstraints works. still investigating why.
update: trying set layoutmargins before view had been added superview (in init). didn't work. did work setting constraints in init, relative layoutmarginsguide, setting layoutmargins in viewdidmovetosuperview.
Comments
Post a Comment