Search code examples
iosswiftviewviewcontrolleruiappearance

How to auto layout an app for different devices.


Apologies in advance for the basic nature of this question. I'm happy to be redirected to a previously answered version of this question, but haven't found it yet.

I just finished up the majority of my first app, and am concerned I might have set it up in the wrong way.

My app looks "good" on an iphone7, but when I change the device to a 7+ there is empty space on the bottom and right edges of the view controllers, and when I run it on an iphone 5, the view doesn't fit.

Is there a way to make the view of my app automatically stretch/condense to any device? Or, is this way more complicated that I anticipated? I want to believe there's an easy solution but I haven't found it yet.

Thanks!


Solution

  • Ok so this is gonna be a long task for you. I'll list down the topics you will need to learn in order to get it right.

    1. StackView
    2. Content Hugging Priorities / Compression Resistance Priorities
    3. Constraint priorities
    4. Size Classes for different UI elements

    Useful links:

    1. Official Tutorials on some mysteries of Autolayout(Part 1 and Part 2).
    2. Official Guide on Autolayout.
    3. other online resources

    as rightly mentioned by J. Doe, The answer is in your question