Where to set translatesAutoresizingMaskIntoConstraints in Xcode 4.5 Where to set translatesAutoresizingMaskIntoConstraints in Xcode 4.5 ios ios

Where to set translatesAutoresizingMaskIntoConstraints in Xcode 4.5


I'm late to this question, but the mentioned option is still missing in Xcode 5 & 6, so the question is still meaningful.

Actually, we can always set a value to any property of a view/control/object by adding a User Defined Runtime Atribute in Storyboard (Interface Builder) like the following screenshot.

And it also works for translatesAutoresizingMaskIntoConstraints. So the question could be solved.

enter image description here


This is a great question - and one I've tried to find an answer to myself. Sadly, it looks like there is no "quick fix". Currently, Apple considers Constraint-based layout Opt-in - even naming a section of the UIView Class Reference:

Opting in to Constraint-Based Layout

But that Opt-in is not global. I presume this is because not everything looks good if you just turn Springs & Struts into Constraints. Some UI elements break, or you would get a ton of unsatisfiable constraints errors.

I can think of one possible solution - I have not tried it myself, but you could make a category on UIView that sets all UIView objects to return NO for - (BOOL)translatesAutoresizingMaskIntoConstraints. While I do not know what this would break, it would globally set translatesAutoresizingMaskIntoConstraints to NO.

Here is a good introduction to Categories if you want to learn more about them!


When u have to change the size or position of your subview. Use (BOOL)translatesAutoresizingMaskIntoConstraints method before you set the frame of your subview.

[self.benchmarkButton removeFromSuperview];[self.benchmarkButton setTranslatesAutoresizingMaskIntoConstraints:YES];[self.benchmarkButton setFrame:CGRectMake(20, self.benchmarkButton.frame.origin.y+40, 260, 30)];[self.benchmarksView addSubview:self.benchmarkButton];

Thats way your subview will not fight from constraints as it is default (AutoLayout) in Xcode 4.3 and later. Thanks