【发布时间】:2020-07-07 06:37:55
【问题描述】:
在使用SwiftUI 的iOS 应用程序中,我使用这种代码设置了警报:
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)))
但我的试验都没有奏效。
如果有人知道要走的路,请告诉我。
【问题讨论】:
-
这是当前版本的 swiftUI 无法做到的。在 wwdc 和 ios 14 上展示的 beta xcode 是可能的
-
dismissButton 需要一个 Alert.Button。只有少数可用 Text() .. 所以没有机会用背景设置它的样式。唯一的选择可能是创建自己的 Alert.Button。不确定,是否可以通过扩展来实现
标签: ios swiftui customization alert