daniyalmaster693/MacToastKit
A minimal toast library for macOS
Install
Compatibility: macOS 13+
Add https://github.com/daniyalmaster693/MacToastKit in the “Swift Package Manager” tab in Xcode.
Features
- Minimal and Native Design
- Customizable Messages and Icons
- Customizable durations
- Adjustable Positioning
- Dismiss to Click
- Show's on active display
Usage
Call the showToast() function when you want to display a message. That's it.
import SwiftUI
import MacToastKit
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
Button("Delete task") {
let toast = ToastWindowController()
toast.showToast(
message: "Deleted Task",
icon: Image(systemName: "trash.fill"),
duration: 3,
position: .bottomCenter(100)
)
}
}
}
}Parameters
The showToast() function supports parameters to control what it displays and how it behaves.
- message: A string that describes the purpose of the toast
- icon: An optional icon that displays with the text
- duration: An optional double value that controls how long the toast will be visible
- position: Controls the position of the toast on the user's screen, with an offset parameter
Template Toasts
You can create template toasts for messages that are repeatedly used throughout your app.
import SwiftUI
import MacToastKit
func showSuccessToast(
_ message: String = "Action Completed",
icon: Image? = nil,
duration: TimeInterval = 3,
position: ToastPosition = .bottomCenter(100)
) {
DispatchQueue.main.async {
let toast = ToastWindowController()
toast.showToast(
message: message,
icon: icon ?? Image(systemName: "checkmark.circle.fill"),
duration: duration,
position: position
)
}
}
func showErrorToast(
_ message: String = "Action Failed",
icon: Image? = nil,
duration: TimeInterval = 3,
position: ToastPosition = .bottomCenter(100)
) {
DispatchQueue.main.async {
let toast = ToastWindowController()
toast.showToast(
message: message,
icon: icon ?? Image(systemName: "x.circle.fill"),
duration: duration,
position: position
)
}
}
Showcase
License
This project is licensed under the MIT license.
Package Metadata
Repository: daniyalmaster693/MacToastKit
Homepage: https://swiftpackageindex.com/daniyalmaster693/MacToastKit
Stars: 31
Forks: 1
Open issues: 1
Default branch: main
Primary language: swift
License: MIT
Topics: macos, notifcations, package, swift, swiftlibrary, swiftui, toast, user-interface
README: README.md