ios - Auto Layout defining constraints -
i have 2 buttons on uiview
. want horizontal distance between these 2 buttons should, 20% width of superview?
any this?
you can accomplish using empty dummy view in between 2 buttons, width 20 % of width of superview.
in code, this:
// important thing here buttons flush against spacer [superview addconstraints: [nslayoutconstraint constraintswithvisualformat:@"[button1]-0-[spacer]-0-[button2]" options:0 metrics:nil views:@{@"button1" : button1, @"button2" : button2, @"spacer" : spacer}]]; // here, set width of spacer 20% of super view [superview addconstraint: [nslayoutconstraint constraintwithitem:spacer attribute:nslayoutattributewidth relatedby:nslayoutrelationequal toitem:superview attribute:nslayoutattributewidth multiplier:0.2 constant:0]];
Comments
Post a Comment