How to set the frame of a view to fill its parents width and height

Oscar de la Hera Gomez
Two flowers that represents SwiftUI and XCode side by side with the text “Size Views to fill Screen” beneath it.

Add a frame modifier and set the maxWidth and/or maxHeight to .infinity.

A screenshot of XCode showing the code that we provided to demonstrate the solution.

The code for the demonstration above can be found at the tutorials/ui/fill-parent-view branch of our open source tutorial linked below.

It comes with four views that demonstrate the functionality:

  • noFill - A View that is as big as its contents.
  • fillWidth - A View whose height fits its content and width matches that of its parent.
  • fillHeight - A View whose width fits its content and height matches that of its parent.
  • fillWidthAndHeight - A View that is as fills as its parent.

Looking to learn more about SwiftUI, Swift, Design and Technology?

Search our blog to learn more about Swift, SwiftUI, design and technology.

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details