Often when working with AutoLayout programmatically something can go wrong. Constraints that you created just not work or program fails. There are most popular mistakes that can happen
1. Forgot to addSubView method
You simply forgot to add your view as subview to parent view.
2. Forgot to set translatesAutoresizingMaskIntoConstraints property to false
Another important thing to remember. You need to enable AutoLayot for your view. So, if you forgot to set translatesAutoresizingMaskIntoConstraints to false then your view will not using AutoLayout.
3. Forgot to activate constraint
When you create new constraint it is not enough to make it work. You have to activate it.
4. Your views in different hierarchies
You can only add constraint to views that are in the same hierarchy. In other words - constraint for your view must operate with parent view (or view from the same hierarchy).
5. You must specify position and size both. Directly or indirectly
When you create constraints you need to specify size and position for your view. In other case your constraints will not work.
Directly specifying example (setup center position and width and height)
Indirectly specifying example (setup top, bottom, leading and width)