Introduction

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

RGB Picker is looking great! Users can use the app on their iPhone and browse the total range of RGB colors to find the perfect combination of red, green, and blue. The code is looking great too. It’s well-organized and way less repetitive than before.

And because SwiftUI works on all of Apple’s platforms, RGB Picker is ready to run on the iPad, too. Isn’t that cool?

Image: RGB Picker running on an iPad simulator on the landscape orientation
Image: RGB Picker running on an iPad simulator on the landscape orientation

While the app is running great on the iPad, it still has a couple of layout problems on the iPhone. Take a look at what happens when you rotate the device to match the landscape orientation of the iPad.

Image: RGB Picker running on an iPhone simulator on the landscape orientation. The title, the slider to choose the blue amount and the button to set the color are out of bounds of the screen
Image: RGB Picker running on an iPhone simulator on the landscape orientation. The title, the slider to choose the blue amount and the button to set the color are out of bounds of the screen

Not good. Part of the UI is off screen. The title, part of the color rectangle, blue slider and button are out of bounds.

SwiftUI supports landscape orientation out of the box, but the code you wrote to build the UI does not. The app arranges views vertically and ends up taking all the limited vertical space on-screen when the device is in landscape orientation, pushing part of the view out of bounds.

You’re going to fix that next so that users can use RGB Picker in any orientation they’d like.

In this lesson, you’ll:

  • Learn the importance of Portrait and Landscape layouts and how they differ depending on the device.
  • Learn about the possible solutions to this kind of issue and how ScrollView can be a quick fix.
  • Use Device Size Classes and switch between two views depending on the orientation of the device.

Additionally, you’ll continue refactoring code to keep your project clean and organized while improving RGB Picker.

See forum comments
Download course materials from Github
Previous: Quiz: Creating Custom SwiftUI Views Next: Instruction 1