Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Design an iPhone App for Any Screen Size

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Designing an iPhone app that looks great on every model—from the compact iPhone SE to the large Pro Max—requires a flexible layout that adapts to different widths, heights, and safe areas. This guide walks you through the essential steps using Auto Layout and Size Classes in Xcode, so your interface scales gracefully without extra code. You'll need a Mac with Xcode installed and a basic understanding of the Interface Builder.

What You'll Need

  • Mac running macOS Ventura or later
  • Xcode (latest stable version from the Mac App Store)
  • An iOS project (SwiftUI or UIKit) with a storyboard or SwiftUI view
  • Basic familiarity with the Xcode Interface Builder

Step-by-Step

  1. Start with a flexible base. Open your storyboard and select the root view controller. In the Attributes Inspector, ensure the Size is set to Freeform or Inferred—not a fixed device size. This lets the layout adjust to any screen.
  2. Use Auto Layout constraints. For every UI element, add constraints that pin it to the safe area or to other elements. Avoid fixed widths and heights for critical views; instead, use leading/trailing/top/bottom constraints and let the system calculate sizes. For example, a button should have leading and trailing constraints with a fixed height, not a fixed width.
  3. Set content hugging and compression resistance. For labels and buttons, set the Content Hugging Priority and Content Compression Resistance Priority to keep text from clipping. Higher compression resistance means the view resists shrinking; higher hugging means it resists growing. Adjust these in the Size Inspector per element.
  4. Use Stack Views for groups. Place related elements (like a label above a text field) into a UIStackView. Set the axis, spacing, and distribution. Stack views automatically distribute space and adapt to screen width. For vertical stacks, set leading/trailing constraints; for horizontal, set top/bottom and center.
  5. Handle different size classes. In the storyboard, use the bottom toolbar to switch between Compact and Regular width/height. For each size class, you can add or remove constraints, change fonts, or hide elements. For example, on compact width (portrait iPhone), you might stack two columns vertically; on regular width (landscape or iPad), show them side-by-side.
  6. Design for safe areas. Always constrain to the safe area, not the view edges. The safe area accounts for the notch, home indicator, and rounded corners. In Interface Builder, use the Safe Area layout guides (shown as dashed lines). This prevents content from being obscured.
  7. Use dynamic type for text. Instead of fixed font sizes, use text styles (e.g., Headline, Body) that scale with the user's accessibility settings. In the Attributes Inspector, set the font to a text style and enable Automatically Adjusts Font for labels.
  8. Test on multiple simulators. Run your app on simulators for iPhone SE (3rd gen), iPhone 15, and iPhone 15 Pro Max. Check for broken layouts, overlapping elements, or clipped text. Use the View as device selector in the storyboard to preview different sizes without running.
  9. Handle rotation and orientation. If your app supports landscape, ensure your constraints work both ways. Use size classes to adjust the layout for regular width (landscape). For example, a horizontal stack might become vertical in compact height.
  10. Use SwiftUI's adaptive layout (if applicable). In SwiftUI, use HStack, VStack, and GeometryReader to create flexible layouts. Use @Environment(\.horizontalSizeClass) to change layout based on size class. For example, show a sidebar in regular width and a tab bar in compact.
  11. Add constraints for different screen sizes. For elements that need a minimum width, use Greater Than or Equal constraints. For example, a button might have a minimum width of 100 points, but can grow. Use Less Than or Equal for maximum sizes.
  12. Preview and iterate. Use the Assistant Editor's Preview to see your layout on multiple devices simultaneously. Adjust constraints until the layout looks balanced on all sizes.

Common Mistakes

  • Setting fixed widths or heights on elements that should stretch.
  • Ignoring the safe area, causing content to be hidden under the notch or home indicator.
  • Using too many constraints that conflict, resulting in unsatisfiable layouts (red lines in Interface Builder).
  • Forgetting to test on the smallest device (iPhone SE) where text may truncate.
  • Not enabling dynamic type, so text doesn't scale for accessibility.

Tips

  • Start with a simple layout and add complexity gradually.
  • Use stack views as much as possible—they simplify constraint management.
  • Set the Horizontal and Vertical content compression resistance to 750 and hugging to 250 for labels to avoid clipping.
  • Use NSLayoutConstraint.activate in code for programmatic constraints, but prefer storyboards for visual clarity.
  • Test with larger accessibility text sizes to ensure your layout doesn't break.

Troubleshooting

If your layout doesn't adapt as expected, try these steps:

  • Check for constraint conflicts. In the console, look for warnings like "Unable to simultaneously satisfy constraints." Open the Issue Navigator (Cmd+4) and fix the conflicting constraints by removing or adjusting priorities.
  • Ensure the safe area is used. If content is under the notch, select the view and check that its constraints reference the Safe Area, not the superview's edges.
  • Verify size class overrides. If a layout works in portrait but not landscape, you may have accidentally added a size-class-specific constraint. Go to the Size Inspector and check if the constraint has a size class override (look for a small + button). Remove or adjust it.
  • Reset to suggested constraints. If you're stuck, select the view and choose Editor > Resolve Auto Layout Issues > Update Frames to let Xcode recalculate frames based on constraints.
  • Test on a physical device. Simulators can sometimes mask issues. Run on a real iPhone to see how the layout feels.

Frequently Asked Questions

  1. Do I need to create separate storyboards for each iPhone size? No. Auto Layout and size classes let one storyboard adapt to all sizes. Separate storyboards are only needed for iPad vs. iPhone if you want entirely different layouts, but even then, size classes can handle it.
  2. What is the difference between points and pixels? Points are the logical units used in iOS layouts; pixels are the physical screen pixels. On a Retina display, 1 point equals 2 or 3 pixels. Auto Layout works in points, so you don't need to worry about pixel density.
  3. How do I make a button stretch to fill the screen width? Add leading and trailing constraints to the button's superview (or safe area) with a constant of, say, 16 points. Set the height constraint to a fixed value. The button will automatically stretch to fill the available width.
  4. Can I use the same layout for iPad and iPhone? Yes, but you'll likely want to use size classes to adjust the layout. For example, on iPad (regular width), you might show a master-detail split view, while on iPhone (compact width), you show a navigation stack.
  5. What is the best way to handle text that is too long? Set the label's Line Break to Word Wrap and allow it to grow vertically. Use constraints that pin the label's top and leading/trailing, but not the bottom, so it can expand. Also, enable Automatically Adjusts Font to shrink the font if needed.
  6. How do I support landscape orientation? Use size classes to change the layout when the width becomes regular (landscape on iPhone). For example, you might change a vertical stack to horizontal. Also, ensure your constraints work when the height is compact.