SwiftUI - centre content on a List

How can I make this arrow on the centre of the list?

struct ProductsList : View { var body: some View { VStack { List { Image(systemName: "shift") } } } 

}

enter image description here

3 Answers

You may just wanna use some Spacers.

struct ProductsList : View { var body: some View { VStack { List { HStack { Spacer() Image(systemName: "shift") Spacer() } } } } } 
0

I would suggest to use ViewModifier:

struct CenterModifier: ViewModifier { func body(content: Content) -> some View { HStack { Spacer() content Spacer() } } } 

so that in your list, if you have more different type of UI elements its more convenient way to do so:

struct ExampleList: View { var body: some View { List { Image(systemName: "shift").modifier(CenterModifier()) SomeOtherView().modifier(CenterModifier()) } } } 

Try this:

var body: some View { List { GeometryReader { geometry in VStack(alignment: .center) { Image(systemName: "shift") }.frame(width: geometry.size.width) } } } 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like