繁体   English   中英

SwiftUI ActionSheet 如何更改取消颜色

[英]SwiftUI ActionSheet how can i change cancel color

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

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

暂无
暂无

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

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