简体   繁体   English

SwiftUI ActionSheet 如何更改取消颜色

[英]SwiftUI ActionSheet how can i change cancel color

I have an action sheet that has 5 elements and a cancel button.我有一个包含 5 个元素和一个取消按钮的操作表。 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 .我见过这个SwiftUI ActionSheet 每个动作都有不同的颜色 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 代码:

.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没有明确的方法,但作为解决方法,您可以使用破坏性样式来显式命名取消按钮,并使用 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
        }    
    ])
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM