问题
I have 2 views that I have taken in storyboard but I haven't set any layouts in the storyboard.I want to set them by code.So here is what I did:
I read about autoResizingMask property of a view and 'translatesAutoResizingMaskIntoConstraints'.So setting 'translatesAutoResizingMaskIntoConstraints' to 'NO' makes sense.So I have done that but still I' not able to set the constraints programmatically.Now,as some constraints are automatically set in storyboard when we take the views from storyboard,I tried:
[self.view removeConstraints:[self.view constraints]];
After doing this,it removes all default constraints from the superview(i.e. self.view).But still I am not able to set constraints from code.What should I do?I need some guidance.
Here is my code that I have been using:
[self.view setTranslatesAutoresizingMaskIntoConstraints:NO];
NSLayoutConstraint *layouts1 = [NSLayoutConstraint constraintWithItem:_redView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:_yellowView attribute:NSLayoutAttributeWidth multiplier:3.0f constant:100.0f];
[self.view addConstraint:layouts1];
来源:https://stackoverflow.com/questions/33431386/constraints-set-in-code-doesnt-reflect-in-the-outputautolayout-ios