Saturday, 7 September 2013

can I set constraints directly to superview in a custom view?

can I set constraints directly to superview in a custom view?

A pretty simple question I reckon:
one UIViewController
one custom UIView
The controller only does:
-(void)loadView{
[super loadView];
self.sideMenu = [[sideMenuView alloc]init];
[self.view addSubview:self.sideMenu];
}
and in the UIView I would like to do something like:
self.translatesAutoresizingMaskIntoConstraints = NO;
NSLayoutConstraint *constraint = [NSLayoutConstraint
constraintWithItem:self attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual toItem:self.superview
attribute:NSLayoutAttributeLeading multiplier:1 constant:100];
[self.superview addConstraint:constraint];
So that when I create the UIView in the controller its constraints is
already set in relation to the controller.
I have tried and nothing crashes but the UIView gets realy weird x and y
coords
Maby I need to update the constraints? Or maby this isnt at all possible?
tnx

No comments:

Post a Comment