1

In XCode, I would like to have a different layout according to the device used. For example, if it's an iPad, I would like an image to be aligned to the left with some text to the right, while on an iPhone 7, I would like the image to be above the text. A little like a responsive website where we can manage the layouts according to the device width.

Is it possible in XCode using Storyboards? Or should I just keep working using the auto layout feature?

Thanks!

fraxool
  • 3,199
  • 4
  • 31
  • 57
  • 3
    you really should use autolayout, one day when apple decides to add a new screen size for their phones, your apps layout will break without an update which could take you a while to push out depending how much UI your app has – Fonix Jan 10 '17 at 08:34

2 Answers2

1

With the help of autolayout, we can achieve the different layout on different screen sizes. You can change constants values for difference size classes in Storyboard.

Step:-

  • Select the constant we want to change the value in other size classes.
  • In the attribute inspector after selecting the constant, you can see the value of the constant. Right beside you can see the PLUS (+) sign, left of the "constant".
  • Click on it and select your size class that you want.
  • Give it a new value.

enter image description here

pkc456
  • 8,350
  • 38
  • 53
  • 109
0

I found this answer to answer your question.

However, if as you said you only want different displays for iPads and iPhones, you can differentiate them in this simple way:

if UIDevice.current.userInterfaceIdiom == .pad {

    // Show iPad UI

} else {

    // Show iPhone UI

}
Community
  • 1
  • 1
Bright
  • 5,699
  • 2
  • 50
  • 72