Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Format number inside image bubble

I’m having some trouble understanding how to properly align items in top of each other:

So I have the following VStack:

VStack(spacing: 0) {
    Text("\(placeC.places.count)")
    Image("map-pin-full-cluster-1")
        .renderingMode(.template)
        .resizable()
        .frame(width: 35, height: 35)
        .foregroundColor(.brown)
} //: END VStack

Which produces the following output:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

What is the best way to have the number inside the circle? Is there a recommended SwiftUI builder that you all use that I can explore?

>Solution :

Typically you would use an .overlay:

Image("map-pin-full-cluster-1")
    .renderingMode(.template)
    .resizable()
    .frame(width: 35, height: 35)
    .foregroundColor(.brown)
    .overlay(alignment: .top) {
        Text("\(placeC.places.count)")
    }

or a ZStack:

ZStack(alignment: .top) {  // other alignments: .center, .bottom, .leading, .trailing
    Image("map-pin-full-cluster-1")
        .renderingMode(.template)
        .resizable()
        .frame(width: 35, height: 35)
        .foregroundColor(.brown)
    Text("\(placeC.places.count)")
        .padding(.top, 4)  // adjust this to move the text up/down
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading