Friday, September 18, 2026
HomeiOS Developmentios - SwiftUI Button formatting concern (Bug?)

ios – SwiftUI Button formatting concern (Bug?)

[ad_1]

I’ve a button arrange in ContentView with the modifiers: padding, background, font and foregroundColor.

The preview display screen

However when it runs on the simulator, that is what occurs to the button:

The simulator display screen

Any concept on the way to clear up this? The code is as follows:

import SwiftUI

 struct ContentView: View {
    
    @State var leftDiceNo = 1
    @State var rightDiceNo = 1
    
    var physique: some View {
        ZStack{
            Picture("background")
                .resizable()
                .edgesIgnoringSafeArea(.all)
            VStack{
                Picture("diceeLogo")
                
                Spacer()
                
                HStack{
                    DiceView(n: leftDiceNo)
                    DiceView(n: rightDiceNo)
                }
                .padding(.horizontal)
                
                Spacer()
                
                Button("Roll"){
                    leftDiceNo = Int.random(in: 1...6)
                    rightDiceNo = Int.random(in: 1...6)
                }
                .padding(5.0)
                .background(Colour.pink)
                .font(.system(dimension: 45))
                .foregroundColor(Colour.white)
                
            }
            
        }
    }
}
struct DiceView: View {
    
    let n: Int
    
    var physique: some View {
        Picture("cube(n)")
            .resizable()
            .aspectRatio(1, contentMode: .match)
            .padding()
    }
}

struct ContentView_Previews: PreviewProvider {

        static var previews: some View {

        ContentView()

    }

}

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments