ios - How can I create NSLayoutConstraint object that is exactly same as @"H:|-10-[view]" in code? -
i've been trying figure out how create nslayoutconstraint
object using nslayoutconstraint
's constraintwithitem method equivalent code below.
nsarray *constraints = [nslayoutconstraint constraintswithvisualformat:"@h:|-10-[view]" options:0 metrics:nil views:nsdictionaryofvariablebindings(view)]; nslayoutconstraint *rightmarginconstraint = [constraints firstobject];
i've tried codes below:
nslayoutconstraint* rightmarginconstraints = [nslayoutconstraint constraintwithitem:view attribute:nslayoutattributeleading relatedby:nslayoutrelationequal toitem:superview attribute:nslayoutattributeleft multiplier:1.0f constant:10.0f];
but doesn't quite same thing, , it's different on console when printed out. want constraint printed out "h:|-10-[view]"
on console.
does know how create 1 works both ios7 , 8? (i found there new attribute options ios 8, still back upwards ios 7)
thanks in advance!
///////// edit ////////
actually 2nd block of code produced same constraint on simple view & superview. however, i'm having issue on tableviewcells , i'm getting result below:
this want , produced code similar first block of code
<nslayoutconstraint:0x7fc050f481c0 h:|-(10)-[uiview:0x7fc050f48070] (names: '|':uitableviewcellcontentview:0x7fc050f39310 )>
the sec block of code produces constraint similar output below
<nslayoutconstraint:0x7b6513d0 view:0x7b64cdf0.leading == uitableviewcellcontentview:0x7b64cd10.left>
///edit 2/// i'm getting output looks code below used matched attributes.
<nslayoutconstraint:0x7d695c70 customborderview:0x7d4cb0f0.right == uitableviewcellcontentview:0x7d4cb010.right + 10>
///edit 3///
i figured order of item matters. swapped argument constraintwithitem: , toitem: , outputs wanted. thanks!
nslayoutattributeleft
not same nslayoutattributeleading
. seek this:
nslayoutconstraint* rightmarginconstraints = [nslayoutconstraint constraintwithitem:view attribute:nslayoutattributeleading relatedby:nslayoutrelationequal toitem:superview attribute:nslayoutattributeleading multiplier:1.0f constant:10.0f];
or this:
nslayoutconstraint* rightmarginconstraints = [nslayoutconstraint constraintwithitem:view attribute:nslayoutattributeleft relatedby:nslayoutrelationequal toitem:superview attribute:nslayoutattributeleft multiplier:1.0f constant:10.0f];
both of these give me desired output. mixing ...left
, ...leading
gives me unwanted output.
ios cocoa-touch autolayout nslayoutconstraint
No comments:
Post a Comment