Je suis nouveau sur SwiftUI et je voudrais de l'aide concernant le positionnement d'un bouton personnalisé que je ne parviens pas à centrer. J'ai utilisé VStack et HStack pour essayer de centrer le bouton en bas, mais le bouton continue de s'aligner à gauche. Toute aide sera appréciée.
struct ContentView: View { var body: some View { VStack { NavigationView { Section { VStack(alignment: .leading) { Text("Meal Description").foregroundColor(.green) Spacer() NavigationLink(destination: PoundedYam()) { Text("Pounded Yam & Egusi Soup") } NavigationLink(destination: YamPepSoup()) { Text("Yam and Pepper Soup") } NavigationLink(destination: JollofRice()) { Text("Jollof Rice & Plantain") } Spacer() .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .topLeading) }.padding() } Section { Image("africanfoods") .resizable() .frame(width: 275.0, height: 250.0) .clipShape(Circle()) .overlay(Circle().stroke(Color.black, lineWidth: 5)) .scaledToFit() } VStack { //For Button Spacer() Button( action: {}, label: { Text("Create Order") }) } .navigationBarTitle(Text("Menu")) } //NavView End } //VStack End } }
3 Réponses :
Ce n'est peut-être pas la solution la plus élégante mais cela fonctionne:
HStack() { Spacer() Button( action: {}, label: { Text("Create Order") }) Spacer() }
Vous pouvez ajouter .frame (maxWidth: .infinity)
au Button
. Cela augmentera également la capacité d'apprentissage.
Button("Create Order") { } .frame(maxWidth: .infinity)