SwiftUI: Layout & Interfaces

Nov 18 2021 · Swift 5.5, iOS 15, Xcode 13

Part 2: Aligning Views

12. Alignment Guides

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 11. Challenge: Align Nested Stacks Next episode: 13. Custom Alignment

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Notes: 12. Alignment Guides

This course was originally recorded in 2019. It has been reviewed and all content and materials updated as of October 2021.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

With your knowledge of how to nest Stacks, and alignment, you have the capability to solve a lot of layout challenges where not every view is aligned in exactly the same way as its neighbors.

        .alignmentGuide(/*@START_MENU_TOKEN@*/ /*@PLACEHOLDER=Guide@*/.top/*@END_MENU_TOKEN@*/) { dimension in
          /*@START_MENU_TOKEN@*/ /*@PLACEHOLDER=Value@*/dimension[.top]/*@END_MENU_TOKEN@*/
      }
.alignmentGuide(VerticalAlignment.center)
dimensions
.alignmentGuide(VerticalAlignment.center) { $0 }
.alignmentGuide(VerticalAlignment.center) { $0.height }
{ $0[.bottom] }
$0[.top]
        .frame(width: 60)
        .alignmentGuide(VerticalAlignment.center) { $0[.top] }

      Text("Alignment == 😻!")
$0[.bottom]
        .multilineTextAlignment(.center)
        .alignmentGuide(VerticalAlignment.center) { $0[.top] }
.alignmentGuide(VerticalAlignment.center) { $0[.bottom] * 3.5 }
.alignmentGuide(VerticalAlignment.center) { $0[.top] - 200 }
.alignmentGuide(VerticalAlignment.center) { _ in 300 }
VStack {
.alignmentGuide(HorizontalAlignment.center) { $0[.bottom] * 3.5 }
.alignmentGuide(HorizontalAlignment.center) { $0[.leading] }
VStack(alignment: .leading) {
.alignmentGuide(.leading) { $0[.top] - 200 }
.alignmentGuide(.leading) { $0[.trailing] }
.alignmentGuide(.leading) { $0[HorizontalAlignment.center] }
        .frame(width: 60)

      Text("Alignment == 😻!")
        .multilineTextAlignment(.center)

      Image("Xcode Magic")