Skip to content

About

A Swift package for creating branded Buy Me a Coffee links in SwiftUI.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

3 stars

Watchers

3 watching

Forks

Repository files navigation

SwiftUI BuyMeACoffee

A Swift package for creating branded Buy Me a Coffee links in SwiftUI.

Overview

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.

Requirements

  • Swift 6.3+
  • iOS 15+

BuyMeACoffee is written in Swift and is available on iOS platforms.

Installation

  1. Add BuyMeACoffee to the dependencies in your Package.swift file:

    let package: Package = .init(
        ...
        dependencies: [
            .package(
                url: "https://github.com/alexandrehsaad/swiftui-buymeacoffee.git",
                from: "1.0.0"
            )
        ],
        ...
    )
  2. Add the BuyMeACoffee product to the dependencies of the target that will import it. Replace YourTarget with the name of that target:

    let package: Package = .init(
        ...
        targets: [
            .target(
                name: "YourTarget",
                dependencies: [
                    .product(
                        name: "BuyMeACoffee",
                        package: "swiftui-buymeacoffee"
                    )
                ]
            )
        ],
        ...
    )
  3. Import the package in your source code:

    import BuyMeACoffee

Demonstration

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.

Buy me a coffee

Documentation

You can read more about this package by visiting the Documentation.

Contributing

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.

License

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.

About

A Swift package for creating branded Buy Me a Coffee links in SwiftUI.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

3 stars

Watchers

3 watching

Forks

Releases

Sponsor this project

Contributors

Languages