This is the code of button
Why does it work if I click in the center and if I click on the side it doesn't?
This is the code of button
Why does it work if I click in the center and if I click on the side it doesn't?
Because of clickable view frames are different..
You will understand better if you examine the code example below.
VStack {
Button("Button1") {
print("Button clicked")
}
.frame(width: 350, height: 50, alignment: .center) //Button View frame
.background(.purple)
Button {
print("Button clicked")
} label: {
//Clickable view frame
Text("Button2")
.frame(width: 300, height: 50, alignment: .center)
.background(.green)
}
.frame(width: 350, height: 50, alignment: .center)//Button View frame and You can remove this line if you understand..
.background(.purple)
}
Button1 is your coding style..
If you use to Button2 coding style, your problem will be solved. PS: Green background is clickable frame..