10

I am trying to create an overlay that is larger than the underlying view.

I tried to do this using the overlay() modifier, but the overlay does not seem to be allowed to extend past the bounds of the underlying view.

I realize that this is doable by pulling the overlay up in the hierarchy to a containing view with larger bounds and using a ZStack, but that breaks the flow I'm going for. I want the overlay to be self-contained within the smaller view that creates it (sort of like how the sheet() modifier works).

Is this possible in SwiftUI?

jchitel
  • 2,999
  • 4
  • 36
  • 49

1 Answers1

0

?

    Rectangle()
      .foregroundColor(.gray)
      .frame(width: 100)
      .overlay(
        Rectangle()
          .foregroundColor(.green)
          .frame(width: 200)
          .blendMode(.multiply)
      )

enter image description here

  • Interesting... I think my issue is that I want the overlay to be full-screen. You have set the width to an exact number, whereas I tried to set `maxWidth: .infinity`. How can I force the overlay to extend to the edges of the screen? – jchitel Oct 21 '20 at 04:36
  • GeometryReader. But ZStack is simpler. –  Oct 21 '20 at 05:02