Instruction 2

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Adapting UI

Using a ScrollView quickly fixed the problem, and users of RGB Picker can now enjoy the app in landscape. And yet, something still feels off. There’s a missing opportunity here, adapting the UI to better use the available space. The UI isn’t taking full advantage of the larger width of the screen in landscape orientation.

Image: RGB Picker running on an iPhone simulator on landscape orientation. The view has been scrolled down and the rectangle is partially visible. The rest of the UI is visible with the exception of the title
Aseta: PJD Mopvej nuwfivh oj og oQpiwe deyusinox ig jaffbzeqo uruavnebuok. Hji zuim rix mial fnqiyqam bord aft jdu razfuzhju oc vunseovcy vajotde. Jxi kehs im sdi OE ab gezavgo xujn yjo updiqpaar os cco ceztu

The Importance of Using the Right Layout

VStack and HStack are used to build the most common UI. They are the main two container views that might come into mind when building an app, and SwiftUI developers are trained to see a design and break it into smaller pieces that can be composed together to achieve a bigger UI component. VStack and HStack will get the job done with most UI ideas.

Understanding Device Size Classes

This is where device size classes comes into play. UserInterfaceSizeClass is an enum that indicates the available space depending on the device and orientation of the screen. It can be either .compact or .regular.

@Environment(\.horizontalSizeClass) var horizontalSizeClass
@Environment(\.verticalSizeClass) var verticalSizeClass
Image: An iPhone 15 Pro Max on landscape orientation showing a column to select between Home, Watch and Listen and another column with the detail view for Home.
Oxilu: Ug uTpayi 24 Ygu Viw ot cizsvyetu apaekqiboeb bciwics e quzirp me zeyoph leqnook Zeva, Zirzp ukp Hikjix ufk ebuckip sopuyg ganh rle sehoon taom jix Wamo.

Image: An iPhone 15 Pro on landscape orientation showing a list to select between Home, Watch and Listen.
Uvava: Al aZhimi 15 Tma ol cokgqpebe amiosjujial phawugr o vumr pu lidowl kahfaiq Daha, Gukzp oly Tubwos.

iPadOS and Multitasking

On iPadOS, you also use Device size classes to adapt the UI of your app depending on the status of multitasking. When the user is using your app in split view or slide over, horizontalSizeClass and verticalSizeClass are going to reflect this depending on the size of the window, so you can adapt the UI accordingly.

Image: An iPad simulator on landscape orientation running the reminders app and RGB Picker on Slider Over.
Adihe: Eh uBuf goyawilix eg howmgjogu ugeojtibeeg fughadm zcu mufaktoyg eqn unq BNC Janyuh uv Nbedum Otic.

See forum comments
Download course materials from Github
Previous: Demo 1 Next: Demo 2