SwiftUI ActionSheet 如何更改取消颜色

SwiftUI ActionSheet how can i change cancel color

我有一个包含 5 个元素和一个取消按钮的操作 sheet。我正在尝试将取消按钮的颜色设置为红色,但它不起作用。这个我看过SwiftUI ActionSheet different color for each action。破坏性按钮样式使其他选项卡变为红色,但不知道如何使取消选项卡变为红色。我已将我的取消选项卡更新为以下内容,但颜色仍然是蓝色,任何建议都很好。

.cancel(Text("Cancel")
.font(.system(size: 40.0))
.foregroundColor(Color.red))

下面是我的 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))
    
    ])
}

没有明确的方法,但作为解决方法,您可以对带有 nop 操作的明确命名的取消按钮使用破坏性样式,例如

.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
        }    
    ])
}