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

Location of buttons in SwiftUI

i’m making an app and i have a problem, my interface (buttons, image etc.) placed in the center of the screen. and i want to place them at the top. Here is the code

    var body: some View {
        VStack{
            HStack{
                Button {
                    
                } label: {
                    Image(systemName: "pencil")
                        .resizable()
                        .aspectRatio(contentMode: .fill)
                        .frame(width: 45, height: 45)
                        .clipShape(Circle())
                }
                .hLeading()
                Button {
                    
                } label: {
                    Image(systemName: "calendar")
                        .font(.title2)
                        .foregroundColor(.white)
                }
                Button {
                    
                } label: {
                    Image(systemName: "bell")
                        .font(.title2)
                        .foregroundColor(.white)
                }
            }
            .padding()
        }
        .vTop()
        .hCenter()
        .background(Color("BG"))
        .preferredColorScheme(.dark)
    }

Can anybody help me?enter image description here

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

>Solution :

add Spacer() in your VStack
like this:

    var body: some View {
    VStack{
        HStack{
            Button {
                
            } label: {
                Image(systemName: "pencil")
                    .resizable()
                    .aspectRatio(contentMode: .fill)
                    .frame(width: 45, height: 45)
                    .clipShape(Circle())
            }
            .hLeading()
            Button {
                
            } label: {
                Image(systemName: "calendar")
                    .font(.title2)
                    .foregroundColor(.white)
            }
            Button {
                
            } label: {
                Image(systemName: "bell")
                    .font(.title2)
                    .foregroundColor(.white)
            }
        }
        .padding()

        Spacer()  // <- this
    }
    .vTop()
    .hCenter()
    .background(Color("BG"))
    .preferredColorScheme(.dark)

    
}
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