CustomAlertView is a flexible and customizable alert view for SwiftUI applications. It allows you to create alerts with custom content, titles, and actions.
- Customizable alert content
- Optional title
- Support for cancel and done actions
- Easy integration with SwiftUI views
- Animated presentation and dismissal
- iOS 13.0+
- macOS 10.15+
- tvOS 13.0+
- watchOS 6.0+
- Xcode 11.0+
- Swift 5.1+
You can add CustomAlertView to your project using Swift Package Manager. In Xcode:
- Go to File > Swift Packages > Add Package Dependency
- Enter the repository URL:
https://github.com/SeikoLai/SwiftUI_CustomAlertView.git - Select the version you want to use
There are two main ways to use CustomAlertView in your SwiftUI projects:
You can create and present a CustomAlertView directly in your SwiftUI views:
import SwiftUI
import CustomAlertView
struct ContentView: View {
@State private var showAlert = false
var body: some View {
Button("Show Alert") {
showAlert = true
}
.customAlert(isPresented: $showAlert) {
CustomAlertView(
title: "Alert Title",
message: "This is a custom alert message.",
cancelAction: {
print("Alert canceled")
},
doneAction: {
print("Alert confirmed")
}
)
}
}
}You can use the customAlert modifier to present a custom alert on any view:
import SwiftUI
import CustomAlertView
struct ContentView: View {
@State private var showAlert = false
var body: some View {
Button("Show Alert") {
showAlert = true
}
.customAlert(isPresented: $showAlert) {
VStack {
Text("Custom Content")
Image(systemName: "star.fill")
.foregroundColor(.yellow)
}
}
}
}CustomAlertView offers several customization options:
- Custom content: You can provide any SwiftUI view as the content of the alert.
- Title: An optional title for the alert.
- Actions: You can specify custom actions for the cancel and done buttons.
- Styling: The alert view uses system colors and can be further customized by modifying the view modifiers in the CustomAlertView struct.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions to CustomAlertView are welcome! Please feel free to submit a Pull Request.