Flexible Space and Layout Techniques for SwiftUI: Maximizing Efficiency and Design with StackViews and Spacers

2023-10-13 03:33:08
Let’s first look at the official document flexible space that expands along the major axis of its containing stack layout, or on both axes if not contained in a stack. A view that will extend infinitely will extend infinitely towards the XY axis when placed outside the stack. If placed in the stack, it will extend in the main direction of the stack. SwiftUI layout: If you want to push up in the default setting, add Spacer(). Variation question: Lower right corner? VStack Spacer() HStack Spacer() Text(“Hello, world!”).padding().background(Color.red) The writing method without Spacer can be called a more concise writing method. Use Frame to typeset Text( “Hello, World!”).frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottomTrailing).padding().background(Color.red)overlay (only available following iOS15) overlay official document puts things in In front of the view, similar to ZStackColor.red.overlay(alignment: .bottomTrailing) Text(“Hello, World!”).padding() Here you will find that the Text is stretched out and takes up the entire screen. Use Spacer During typesetting, only the lower right corner is slightly different. Reference video: Simple situation like element. If your picture already uses VStack/HStack, it is reasonable to use Spacer for typesetting. But if it is just a very simple picture and it is not necessary to use Stack+Spacer specifically for typesetting, you can use the above two methods. Comparative writing methods It simply doesn’t have that many components.
1697170515
#SwiftUI #typesetting #artifactSpacer

Leave a Replay