I have an action sheet that has 5 elements and a cancel button. I am trying to make the cancel button color red but it is not working. I have seen this one SwiftUI ActionSheet different color for each action . The destructive button style makes the other tabs red but do not know how to make it red for the cancel tab. I have updated my cancel tab to the following but the color is still Blue, any suggestions would be great.
.cancel(Text("Cancel")
.font(.system(size: 40.0))
.foregroundColor(Color.red))
This below is my code for the ActionSheet:
.actionSheet(isPresented: $showLocationOptions) {
ActionSheet(title: Text("Which city/town is this place in ?"), message: Text("Select a location"), buttons: [
.default(Text(location1)) { },
.default(Text(location2)) { },
.default(Text(location3)) { },
.default(Text(location4)) { },
.default(Text(location5)) { },
.cancel(Text("Cancel")
.font(.system(size: 40.0))
.foregroundColor(Color.red))
])
}
No explicit way, but as workaround you can just use destructive style for explicitly named cancel button with nop action, like
.actionSheet(isPresented: $showLocationOptions) {
ActionSheet(title: Text("Which city/town is this place in ?"), message: Text("Select a location"), buttons: [
.default(Text(location1)) { },
.default(Text(location2)) { },
.default(Text(location3)) { },
.default(Text(location4)) { },
.default(Text(location5)) { },
.destructive(Text("Cancel")){ // << keep as last
// just nop - will be just closed
}
])
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.