AutoLayout Xcode6: Need autolayout constraints for this:

181 views Asked by At

I am new in autolayout (I am good in autoresizing). My requirement is:-

  1. I have 2 view (say blue and green, width and height of both view is 300 pixel in iPhone5). height and width of both view can change according to screen resolution. X and Y origin can also change. 2. In autoresizing I am using this mask to both views for my requirement.

  2. What constraints should I use for this autoresizing masks.

1

There are 1 answers

4
algal On

It is unclear if the blue and green are siblings or if one contains the other.

If the effect you want to achieve can be produced through an autoresizing mask, then you can set translatesAutoresizingMaskIntoConstraints to true and the autoresizing mask will be automatically translated into constraints.

In general, if you want to install constraints manually that mimic the effect of an autoresizing mask with a flexible width and flexible height, then you would do this by creating four constraints maintaining a fixed distance between the edges of the view and the corresponding edges of its superview -- that is, the top of the view and the top of the superview, the bottom with the bottom, the left with left, and right with right.

This could be done with the visual format language with strings like "H:|-(10)-[view]-(10)-|" and "V:|-(10)-[view]-(10)|". This assumes there are no other conflicting constraints that try to set the height and width of the view.