首页 > 解决方案 > 在 SwiftUI 中自定义警报

问题描述

在使用 的iOS应用程序中SwiftUI,我使用这种代码设置了警报:

  Alert(title: Text("Nice Title"),
        message: Text("Some important message for the user."),
        dismissButton: .none)

它有效,但我想更改一个细节。警报有一个蓝色的确定按钮。我想自定义它有一个灰色的确定按钮。

我尝试了一些调整,其中之一是:

  Alert(title: Text("Nice Title"),
        message: Text("Some important message for the user."),
        dismissButton: .default(Text("OK").foregroundColor(.gray)))

但我的试验都没有奏效。

如果有人知道要走的路,请告诉我。

标签: iosswiftuicustomizationalert

解决方案


把它放在显示 z 警报的视图中

    init() {
        UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = .purple1
    }

推荐阅读