iosswiftswiftuiswiftui-alignment-guide

How to use alignment guides in swift ui


Simply what I'm trying to achieve is this enter image description here

The Circle aligned to the bottom left edge of the other image I know that alignment guides should be used in this scenario, but I truly can't understand the concept, that's what I've done so far.

            ZStack(alignment: .bottom) {
                Image("image_placeholder")
                    .resizable()
                    .frame(width: .infinity, height: 220)
                
                Image("image_placeholder")
                    .resizable()
                    .scaledToFill()
                    .aspectRatio(contentMode: .fit)
                    .frame(width: 200)
                    .clipShape(Circle())
                    .alignmentGuide(.bottom) { d in
                        d[VerticalAlignment.center]
                    }
                    .alignmentGuide(.leading) { d in
                        d[HorizontalAlignment.leading]
                    }
            }

But that code displays image in the center bottom, any help?


Solution

  • Change the ZStack alignment to bottomLeading