List{
Button{
//Checking in
}label: {
Text("Check in")
.swipeActions {
Button{
//Checking in
}label: {
Text("Check in")
}.tint(.red)
}
}
}
I've tried to change the color of the background when swiping on a row. Nothing happens. It just keeps being the standard gray.
I've looked at a bunch of other people and it seems like they all put the modifier at the same place as me but they get a different result.
CodePudding user response:
Add .buttonStyle(.plain)
to the Button
in the List:
List {
Button {
//Checking in
} label: {
Text("Check in")
.swipeActions {
Button {
//Checking in
} label: {
Text("Check in")
}
.tint(.red)
}
}
.buttonStyle(.plain)
}
CodePudding user response:
It doesn't work because you are trying to set a swipe action on the Text
, while it's the Button
that's swiping.
Just apply the modifier on the Button
instead of the Text
:
List{
Button{
//Checking in
}label: {
Text("Check in")
}
// The modifier is applied on the Button, not on the Text
.swipeActions {
Button{
//Checking in
}label: {
Text("Check in")
}.tint(.red)
}
}