如何在 SwiftUI 中更改 actionSheet 的文本颜色

Lal*_*lli 9 swift swiftui

我正在尝试在 SwiftUI 中更改 actionSheet 文本的颜色。无法这样做。我试过以下代码

    private var actionSheet: ActionSheet {
    let button1 = ActionSheet.Button.default(Text("Week 1").foregroundColor(.orange)) {
        self.selectedShuffleWeek = "Week 1"
        self.shufflePresented = true
        self.actionSheetPresented = false
    }
    let button2 = ActionSheet.Button.default(Text("Week 2").foregroundColor(Color("GreenColor"))) {
        self.selectedShuffleWeek = "Week 2"
        self.shufflePresented = true
        self.actionSheetPresented = false
    }
    let button3 = ActionSheet.Button.default(Text("Week 3").foregroundColor(Color("GreenColor"))) {
        self.selectedShuffleWeek = "Week 3"
        self.shufflePresented = true
        self.actionSheetPresented = false
    }
    let dismissButton = ActionSheet.Button.cancel {
        self.selectedShuffleWeek = ""
        self.actionSheetPresented = false
    }


    let buttons = [button1, button2, button3, dismissButton]
    return ActionSheet(title: Text("Shuffle"),
                       buttons: buttons)
}
Run Code Online (Sandbox Code Playgroud)

之后,我还尝试更改显示此操作表的视图的强调色,但它不起作用。

小智 10

我已经设法通过在SceneDelegate里面添加以下代码来完成这项工作func scene(_...

UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = Color("GreenColor")
Run Code Online (Sandbox Code Playgroud)

这将更改应用程序中所有 ActionSheets 的强调色。