'How can I position 1 image relative to another in a ZStack in SwiftUI?
I have 2 images in a ZStack. How can I position image "x.circle" to the top right of the image "person.fill"?
ZStack {
Image(systemName: "person.fill")
.font(.system(size: 200))
Image(systemName: "x.circle")
.font(.system(size: 20, weight: .bold))
.foregroundColor(.red)
.background(.white)
.clipShape(Circle())
}
Solution 1:[1]
Use ZStack(alignment: .topTrailing
:
ZStack(alignment: .topTrailing) { // here
Image(systemName: "person.fill")
.font(.system(size: 200))
Image(systemName: "x.circle")
.font(.system(size: 20, weight: .bold))
.foregroundColor(.red)
.background(.white)
.clipShape(Circle())
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | ChrisR |