01
Start with a page that can give up or use space
The goal of iPhone Duo SwiftUI layout adaptation is not to reproduce a screenshot at every size. It is to keep the page understandable as the space available to it changes. A course home page is a useful practice case because it combines a title, a lesson list, progress information, and a clear next action.
Start with a simple structure: a vertical stack for the page, and smaller stacks for related items. For example, keep a course title and brief status together, then place lesson rows below them. This gives SwiftUI a clear hierarchy to lay out. Apple’s basic SwiftUI layout documentation explains how views are arranged and how their size and position relate to their parent.
Before you adjust anything for a device posture, look for fixed width and height values in your own view code. Fixed dimensions are not automatically wrong: a small icon or a compact control may need a consistent size. The risk is using fixed dimensions to define the whole page, then expecting that same composition to fit when the available space changes. A long lesson title, for example, can need more vertical room than a short one.
Build a simple course page first, then inspect these questions:
- Does the lesson title wrap naturally, or does the layout assume it will fit on one line?
- Can the user still see the main action without squeezing every control into a row?
- Does the lesson list remain readable when the page has less width?
- Can the page scroll when its content needs more height?
This is the foundation of SwiftUI adaptive layout: views respond to the space and content they actually have. The Apple talk on adaptive layouts is useful when you want to see how to think about layout choices beyond a single fixed arrangement.
How should a SwiftUI page adapt to iPhone Duo’s outer and inner screens?
Begin with the content hierarchy, not a device measurement. Decide what must remain visible first, such as the course name, current lesson, and action to continue. Then decide whether secondary material can move below the primary content or appear beside it when the available space allows.
For example, a course page might show its lesson list in a vertical flow in a constrained area. When more room is available, the page could show a lesson list next to a selected lesson’s details. The right choice depends on the actual width offered to the view and on how much text the content contains. A wide display does not automatically mean that a sidebar improves the page.
SwiftUI’s ViewThatFits is one option when you have alternative presentations and want SwiftUI to select one that fits. It is not a requirement for every page. For a small course exercise, a flexible stack and sensible scrolling may be clearer. Use an alternative layout only when it solves a visible problem, such as a crowded row or an awkwardly narrow detail area.