![]() The Text views, however, are aligned leading, i.e. It’s important to note here that the default alignment for stacks is centered both horizontally and vertically. The first Text view in the VStack corresponds to the first line of text, shown on the right in the Preview. Text(“Zen and The Art of Motorcycle Maintenance”)Īs you can see in the screenshot above, the Live Preview in Xcode shows 3 Text views organized vertically – top-to-bottom – in a VStack. Here’s an example of a VStack with 3 Text views: Makes you wonder why they didn’t call it an XStack or DStack… VStack, HStack and ZStack in SwiftUI A button or Text view onto a background Image view, for example. Views in a ZStack can overlap, which means it’s ideal for creating UI stacks that overlay other views. The ZStack is in a category of its own, because it groups views together along the z- or depth axis, shown back-to-front. The HStack fits in the same category it’s the same as a VStack, except it groups subviews left-to-right along the horizontal axis. The VStack groups subviews together vertically, along the vertical axis, so top-to-bottom. You can, of course, combine VStacks, HStacks and ZStacks to create complex User Interfaces. Like other SwiftUI views, stacks can contain a maximum of 10 subviews. Stacks are static, so they’re different from List and table views, for example. You can compare stacks in SwiftUI with UIStackView in UIKit.
0 Comments
Leave a Reply. |