itechnician
itechnician

Reputation: 1655

Achieve iphone 4 layout in iphone 5 using autolayout

Since, AutoLayout enables to define dynamic GUIs.In iphone-4, the screen appears as:320x480.png For the boxes 1 , 2 , 3 , 4 ,5 and 6 their CGRect should satisfy the 'x/2' and 'y/2' constraints in all the iphone and ipad as shown.

Is this feasible to achieve it by only specifying constraints available in xib? If yes, please enlighten our thought :)

Upvotes: 0

Views: 59

Answers (1)

jrturton
jrturton

Reputation: 119242

Yes, this is possible. Make sure each view has an equal width and equal height constraint to all the others (you can refer them all back to a single view for simplicity).

Then, pin them either to the superview edges or the edges of each other, as appropriate.

Using VFL to express the constraints, you want something like:

H:|[one][two(==one)]|
H:|[three(==one)][four(==one)]|
H:|[five(==one)][six(==one)]|

V:|[one][three(==one)][five(==one)]|
V:|[two(==one)][four(==one)][six(==one)]|

You can add all of these constraints in interface builder using the pinning menus.

If you're not familiar with VFL, the first line means:

  • H: on the horizontal axis
  • |: superview's leading edge
  • [one]... pin leading edge of one to superview
  • [two(==one)] ... pin leading edge of two to trailing edge of one, and make it the same width
  • | ... Pin trailing edge of two to trailing edge of superview.

Upvotes: 2

Related Questions