我在不断增大按钮尺寸的同时,试图使按钮居中吗?

时间:2020-01-10 05:28:28

标签: swift swiftui

我是SwiftUI的新手。我的问题是每次我尝试增加尺寸时,按钮都会稍微移到屏幕的一侧。我想增加尺寸,同时保持所有内容居中。如果我没有它,我将其删除。我认为我可能不正确地增加了按钮的大小,但我不确定。

import SwiftUI


struct ContentView: View {
@State private var Waifus = ["Rem","Chika","Zero Two","SpeedWagon","Ochaco","Momo","Nezuko","Nami","YunYun","Megumin","Darkness","Reigen","Diane","Froppy"].shuffled()
@State private var CorrectGirl = Int.random(in: 0...2)

@State private var ShowingScore = false
@State private var ScoreTitle = ""
@State private var Points = 0

var body: some View {
    NavigationView {

        ZStack {
            Image("Testing")
                .resizable()
                .scaledToFill()
                .edgesIgnoringSafeArea(.all)

            VStack(spacing: 30) {

                VStack {
                    Spacer()
                    Text("Tap The Waifu")
                        .foregroundColor(.white)
                        .font(.largeTitle)
                    Text(Waifus[CorrectGirl])
                        .foregroundColor(.white)
                        .font(.largeTitle)
                        .fontWeight(.black)

                }


                ForEach(0 ..< 4 ) { number in
                    Button(action: {
                        self.WaifuTapped(number)
                    }) {

                        Image(self.Waifus[number])
                            .renderingMode(.original)
                            .frame(width: 90, height: 90)
                        .clipShape(Circle())
                            .overlay(Circle().stroke(Color.white, lineWidth : 4))



                    }

                }
                Text("You have")
                    .font(.largeTitle)
                    .foregroundColor(.white)
                Text("\(Points) Points")
                    .foregroundColor(.white)
                    .font(.largeTitle)
                    .fontWeight(.black)

                Spacer()
            }
        }
        .alert(isPresented: $ShowingScore) {
            Alert(title: Text(ScoreTitle),message: Text("Your Score is \(Points)"),dismissButton:
                .default(Text("Countinue Weeb")) {
                    self.askQuestion()
                })
        }
    }

}


func WaifuTapped(_ number : Int) {
    if number == CorrectGirl {
        ScoreTitle = "Correct"
        Points += 1
    } else {
        ScoreTitle = "Wrong, The Waifu was \(self.Waifus[number])"
    }

    ShowingScore = true
}

func askQuestion() {
    Waifus.shuffle()
    CorrectGirl = Int.random(in: 0...2)

}

}

0 个答案:

没有答案