首页 > 解决方案 > 在 Alert() 中显示图像的 SwiftUI 扩展

问题描述

在 SwiftUI 中,标准警报具有以下操作:

public struct Alert {
/// Creates an alert with one button.
public init(title: Text, message: Text? = nil, dismissButton: Alert.Button? = nil)

/// Creates an alert with two buttons.
/// The system determines the visual ordering of the buttons.
public init(title: Text, message: Text? = nil, primaryButton: Alert.Button, secondaryButton: Alert.Button)
 }

有没有办法为此警报编写扩展,允许我在标题和消息之间添加图像,所以我可以像这样使用它:

警报(标题:“标题”,图像:“image.png”,消息:“消息文本”,dismissButton:Alert.Button)

在此处输入图像描述

还是我必须为此创建自己的 AlertController?

标签: xcodeimageswiftuialert

解决方案


推荐阅读