簡體   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