A Swift package for creating branded Buy Me a Coffee links in SwiftUI.
BuyMeACoffee provides a branded SwiftUI button that opens a creator's Buy Me a Coffee page. It includes solid and Liquid Glass button styles, selectable tints, and an automatic contrasting border for light and dark interfaces.
The button works with standard SwiftUI label styles and button border shapes, supports Dynamic Type and accessibility settings, and displays the official Buy Me a Coffee logo alongside its matching icon.
- Swift 6.3+
- iOS 15+
BuyMeACoffee is written in Swift and is available on iOS platforms.
-
Add BuyMeACoffee to the dependencies in your
Package.swiftfile:let package: Package = .init( ... dependencies: [ .package( url: "https://github.com/alexandrehsaad/swiftui-buymeacoffee.git", from: "1.0.0" ) ], ... )
-
Add the
BuyMeACoffeeproduct to the dependencies of the target that will import it. ReplaceYourTargetwith the name of that target:let package: Package = .init( ... targets: [ .target( name: "YourTarget", dependencies: [ .product( name: "BuyMeACoffee", package: "swiftui-buymeacoffee" ) ] ) ], ... )
-
Import the package in your source code:
import BuyMeACoffee
Create a button with your username, apply a button style, and optionally observe button taps:
BuyMeACoffeeButton(username: "myusername")
.buttonStyle(.buyMeACoffeeGlass(tint: .yellow))
.onBuyMeACoffeeButtonOpen { url in
print("Opening URL: \(url)")
}The glass style requires iOS 26 or later. Use buyMeACoffee(tint: .yellow) on earlier versions.
Use onBuyMeACoffeeButtonOpen(perform:) to log interactions or record an analytics event. The callback receives the destination
URL before the system is asked to open it. It does not confirm that the page opened or that a donation was completed.
The code above renders the button below. Click it to visit my Buy Me a Coffee page.
You can read more about this package by visiting the Documentation.
Everyone is welcome to contribute to BuyMeACoffee. Please read our Contributing Guide and Code of Conduct.
If you find a bug, please submit a Bug Report. If you would like to suggest a new capability or improvement, please submit a Feature Request.
Report security vulnerabilities using the instructions in the Security Policy.
Distributed under the MIT License. See the Third-Party Notices for materials covered by separate terms.
This is an independent, unofficial project and is not affiliated with, sponsored by, or endorsed by Buy Me a Coffee. The Buy Me a Coffee name, logo, and related artwork belong to Buy Me a Coffee and are not licensed under this project's MIT License.
This repository is a personal educational portfolio project created to explore various technologies. It is distributed without charge and is not intended to suggest a commercial relationship with Buy Me a Coffee.
