SwiftUI extension to display Image in Alert()

723 views Asked by At

In SwiftUI the standard alert has the following actions:

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)
 }

Is there a way to write an extension for this alert that would allow me to add an image between the title, and the message, so I can use it like this:

Alert(title: "Title", image: "image.png", message: "message text", dismissButton: Alert.Button)

enter image description here

Or would I have to create my own AlertController for this?

0

There are 0 answers