Swiftpack.co -  froggomad/BadgeGenerator as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Generate a badge for any UIView
.package(url: "https://github.com/froggomad/BadgeGenerator.git", from: "0.0.4")

Badge Generator

Generate a "badge" (circular label) for any view and place it in the center or any corner of a given view

Badge Generator uses a lightweight, easy to understand approach to make a circular UILabel with the given text

  • platform: iOS
  • extends: UIView
    • @discardableResult public func setBadge(in direction: BadgeDirection, with text: String) -> BadgeLabel
      • adds a new badge to the view in the given location (BadgeDirection)


In your Xcode project, simply go to File -> Swift Packages -> Add Package Dependency. Then use this repo's URL: https://github.com/froggomad/BadgeGenerator


Create, position, and hold reference to a badge

let myView = UIView()
let badge = myView.setBadge(in: .northWest, with: "1")

Increment an integer value by n

This increments the value if it can be converted to Int and update's the badge's text
badge.incrementIntValue(by: 1)

Attempt to increment an integer value, and get the result back

It will fail if the text value can't be converted to Int
let value = badge.incrementIntValue(by: 1)
switch value {
    case let .success(intValue):
    case let .failure(error):

Change a badge's text to "foo"


Remove a badge


Example Badges

These badges are placed on a PreviewProvider, but you can place them on any UIView or in SwiftUI using UIViewRepresentable

Badges In Different Locations Badges In Different Locations

Contributing to this project:

If you notice a bug, or think of a feature you'd like to add, please read our Contributor's Guide


Stars: 10
Last commit: 3 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

3 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API