Search code examples
iosswiftalignmentsize

How to have different layouts for iPhone and iPad (Swift)


In an app that I use, there are 4 rows of buttons with each row containing 3 buttons. When I use the same app on an iPad, the alignment of the buttons becomes 2 rows containing 6 buttons each. Also, the width and height of the buttons change depending on the screen size. I want my app to have the same features but I don't know how to do it. Any help?


Solution

  • 1) You can use Autolayout constraints and size classes to make the view compatible to both iPhone and iPad screen sizes.

    2) You can create and use separate Storyboards or .Xibs each for iPhone and iPad and use accordingly.

    3) if the view does not have complex UI, then you can simply manage by doing it via code by detecting the view size, width height etc i.e whether it is iphone or iPad and then setting the frame, width, height of the UIElements like button, label, image view etc.