ios – How to display values in a better way in Swift


Hi I have a question about Swift. I have been trying to display the game scores like the image(View to show scores)

They can be displayed but the problem is that the text (eg. the score for 10 questions) moves DOWN a bit when the scores are deleted and I think that is not great. I want to know how to fix the text. That would be appreciated if you could help me. Thank you in advance.

VStack {
    Text("The score for 10 questions")
        .foregroundStyle(.white)
        .bold()
    Rectangle()
        .frame(width: 210,height: 2)
        .foregroundColor(.gray)
        .padding(.bottom,10)
    
        ForEach(Array(playerItems.enumerated()), id: \.offset) { offset, item in
            if offset == 0 {
                Text("Best score : \(item.playerScore)")
            }
            else if offset == 1 {
                Text("2nd score : \(String(item.playerScore))")
            }
            else if offset == 2 {
                Text("3rd score : \(String(item.playerScore))")
                  
            }
        }
        .foregroundColor(.white)
        .bold()
        .onTapGesture {
            do {
                try context.delete(model: PlayerItem.self)
            } catch {
                print("Failed to clear all Country and City data.")
            }
        }
}
.frame(height: 100)

View to show scores

I followed the tutorial.

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img