0

I've search quite a bit to find information on view changes in IOS application while using swift. I've trying to do following with a orientation change for a particular view. I've a vie with list of buttons (4) arrange like a list when device in portrait mode but I want to display them as 4 square button in a two row when device switched to landscape mode.

For example, in portrait mode

| Button 1 |


| Button 2 |


| Button 3 |


| Button 4 |

In landscape mode,


| Button 1 Button 2 |

| Button 3 Button 4 |


I don't know if I need to build dynamic view for landscape mode to achieve this? Any ideas/help is appreciated.

Atarang
  • 422
  • 1
  • 6
  • 22

1 Answers1

0

Use the Vary for Traits feature in the InterfaceBuilder.

  1. Select the Vary for Traits option, the check the Width option

    Vary for Traits - Width

  2. Select Landscape under Device options

  3. Make desired changes, in your case rearrange buttons to the new layout

  4. Click the Done Varying button

That's it. InterfaceBuilder has now setup the variations. Switch the orientation to see for yourself.

NSAdi
  • 1,243
  • 9
  • 19
  • I'll definitely try this, just one question does it impact constraints button have in portrait mode? – Atarang Oct 16 '17 at 21:25
  • With this you can set your own constraints for each trait variation. The process of doing this is a little different from normally setting up the constraints. More on that here https://stackoverflow.com/questions/39890055/what-is-vary-for-traits-in-xcode-8 – NSAdi Oct 17 '17 at 00:29
  • This helped. But now I'm wondering if this same technique can be used to create a specific size button for each device type/size? – Atarang Oct 18 '17 at 18:12