SwiftUI: Layout & Interfaces

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

Part 2: Aligning Views

15. ZStacks

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: 14. Challenge: Custom Alignment Guides Next episode: 16. GeometryReader

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: 15. ZStacks

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

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Now that you’ve mastered the first two dimensions, with HStacks and VStacks, it’s time to tackle the third!

    ZStack {
      Image("RWStack")
ZStack(alignment: .) {
ZStack(alignment: .bottomLeading) {
          .foregroundColor(.brightSeafoam)
      }
        .padding()
    }
struct ContentView: View {
  let gradient = LinearGradient(
    gradient: <#T##Gradient#>, startPoint: <#T##UnitPoint#>, endPoint: <#T##UnitPoint#>)

  var body: some View {
    gradient: Gradient(
      stops: [

      ]
    ), startPoint: <#T##UnitPoint#>, endPoint: <#T##UnitPoint#>)
.init(color: .brightSeafoam, location: <#T##CGFloat#>)
.init(color: .brightSeafoam, location: 3 / 8)
.init(color: .brightSeafoam, location: 3.0 / 8),
.init(color: .darkSeafoam, location: <#T##CGFloat#>)
.init(color: .darkSeafoam, location: 1)
      ]
    ),
    startPoint: .topTrailing, endPoint: <#T##UnitPoint#>)
    ),
    startPoint: .topTrailing, endPoint: .bottom
  )
      }
        .padding()
    }
      .overlay(gradient)
  }
      .overlay(gradient)
      .blendMode(.multiply)
  }
      Image("RWStack")
        .resizable()
        .scaledToFit()
        .overlay(gradient)
        .blendMode(.multiply)

      VStack(alignment: .leading) {
        .scaledToFit()

      gradient
        .blendMode(.multiply)

      VStack(alignment: .leading) {
        .blendMode(.multiply)
        .layoutPriority(-1)

      VStack(alignment: .leading) {
ZStack(alignment: .center) {
          .foregroundColor(.brightSeafoam)
      }
    }
          .foregroundColor(.brightSeafoam)
      }
        .alignmentGuide(HorizontalAlignment.center)
    }
.alignmentGuide(HorizontalAlignment.center) { $0[.trailing] }
VStack(alignment: .trailing) {
        .alignmentGuide(HorizontalAlignment.center) { $0[.trailing] }
        .alignmentGuide(VerticalAlignment.center) { $0[.top] }
    }