I already know that we can turn it off by unchecking File Inspector > Interface Builder Document > Use Auto Layout, when we use interface builder.
But in my case, I don't use interface builder nor storyboard, only programmatically created views. Then how can I turn off Auto Layout for iOS 7 using Xcode 5?
How do I turn off Auto Layout for a view from code? tells us that auto layout is turned off if we don't create any constraints for any view. I'm not sure how to create constraints, so I don't if I did some mistakes that lead to auto layout turning on. I want auto layout be off.
When you programmatically create a UIView, there aren't any layout constraints defined. You have to add them manually. If you do have some layoutconstraints configured for a certain view, they can be removed like so:
[view removeConstraints:view.constraints]
So this answer was deleted by Andrew Barber, but its a solid work around and it's helpful so i'm posting it again:
1) Do NOT have views or components laid out in interface builder.
2) Add your views purely programmatically starting with alloc/init and setting their frames appropriately.
3) Done.
Hope that helps!
ps. you can also experiment with stripping constraints from views with:
[view removeConstraints:view.constraints] but i've had more luck with the pure code approach.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With