objective c - How do I call addConstraint from an NSApplicationDelegate in Cocoa? -
i have managed add constraints programatically in custom view class (sub-class of nsview) using following code:
[self addconstraint: [nslayoutconstraint constraintwithitem:self.myobject attribute:nslayoutattributecentery relatedby:nslayoutrelationequal toitem:self attribute:nslayoutattributecentery multiplier:1 constant:0]];
but want similar app delegate (sub-class of nsapplicationdelegate). unsure of object add constraint to.
trying call same way, results in compilation error
[self addconstraint: [nslayoutconstraint constraintwithitem:self.backgroundbox attribute:nslayoutattributecentery relatedby:nslayoutrelationequal toitem:self attribute:nslayoutattributecentery multiplier:1 constant:0]];
i have tried replacing object adding constraint (and object in "toitem" parameter) self.view (the view holding backgroundbox object), [self.window contentview] , self.backgroundbox.superview, either won't compile or don't seem have effect.
can advise on correct way this? want able centre backgroundbox vertically within view (self.view top level view in nib file linked app delegate) (self.backgroundbox box within self.view)
any appreciated. in advance!
note: prefer programatically rather having use ib add constraints)
using xcode5 osx 10.9.3
Comments
Post a Comment