Generate a badge for any UIView

Overview

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)

Installation:

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

Usage:

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):
        print(intValue)
    case let .failure(error):
        print(error)
}

Change a badge's text to "foo"

badge.set("foo")

Remove a badge

badge.remove()

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

You might also like...
Custom UIView class that hosts an array of UIbuttons that have an 'underline' UIView beneath them which moves from button to button when the user presses on them.
Custom UIView class that hosts an array of UIbuttons that have an 'underline' UIView beneath them which moves from button to button when the user presses on them.

Swift-Underlined-Button-Bar Custom UIView class that hosts an array of UIbuttons that have an 'underline' UIView beneath them which moves from button

IHKeyboardAvoiding is an elegant solution for keeping any UIView visible when the keyboard is being shown - no UIScrollView required!
IHKeyboardAvoiding is an elegant solution for keeping any UIView visible when the keyboard is being shown - no UIScrollView required!

IHKeyboardAvoiding An elegant solution for keeping any UIView visible when the keyboard is being shown Requirements IHKeyboardAvoiding Version Objecti

Elissa displays a notification on top of a UITabBarItem or any UIView anchor view to reveal additional information.
Elissa displays a notification on top of a UITabBarItem or any UIView anchor view to reveal additional information.

Elissa Attach a local notification to any UIView to reveal additional user guidance. Usage Example Per default, Elissa will try to align to the center

Twinkle is a Swift and easy way to make any UIView in your iOS or tvOS app twinkle.
Twinkle is a Swift and easy way to make any UIView in your iOS or tvOS app twinkle.

Twinkle ✨ Twinkle is a Swift and easy way to make any UIView in your iOS or tvOS app twinkle. This library creates several CAEmitterLayers and animate

📹 Framework to Play a Video in the Background of any UIView
📹 Framework to Play a Video in the Background of any UIView

SwiftVideoBackground is an easy to use Swift framework that provides the ability to play a video on any UIView. This provides a beautiful UI for login

slider view for choosing categories. add any UIView type as category item view. Fully customisable
slider view for choosing categories. add any UIView type as category item view. Fully customisable

CategorySliderView Horizontal or vertical slider view for choosing categories. Add any UIView type as category item view. Fully customisable Demo Inst

This is an iOS control for presenting any UIView in an UIAlertController like manner
This is an iOS control for presenting any UIView in an UIAlertController like manner

RMActionController This framework allows you to present just any view as an action sheet. In addition, it allows you to add actions around the present

Pipable is an iOS library to implement Picture in Picture for any UIView.
Pipable is an iOS library to implement Picture in Picture for any UIView.

Pipable Pipable is an iOS library to implement Picture in Picture for any UIView. This is done just by conforming to a protocol. The "Audio, AirPlay a

This library allows you to make any UIView tap-able like a UIButton.

UIView-TapListnerCallback Example To run the example project, clone the repo, and run pod install from the Example directory first. Installation UIVie

📹 Framework to Play a Video in the Background of any UIView
📹 Framework to Play a Video in the Background of any UIView

SwiftVideoBackground is an easy to use Swift framework that provides the ability to play a video on any UIView. This provides a beautiful UI for login

Twinkle is a Swift and easy way to make any UIView in your iOS or tvOS app twinkle.
Twinkle is a Swift and easy way to make any UIView in your iOS or tvOS app twinkle.

Twinkle ✨ Twinkle is a Swift and easy way to make any UIView in your iOS or tvOS app twinkle. This library creates several CAEmitterLayers and animate

Codeless drop-in universal library allows to prevent issues of keyboard sliding up and cover UITextField/UITextView. Neither need to write any code nor any setup required and much more.
Codeless drop-in universal library allows to prevent issues of keyboard sliding up and cover UITextField/UITextView. Neither need to write any code nor any setup required and much more.

IQKeyboardManager While developing iOS apps, we often run into issues where the iPhone keyboard slides up and covers the UITextField/UITextView. IQKey

Use any custom view as custom callout view for MKMapView with cool animations. Use any image as annotation view.
Use any custom view as custom callout view for MKMapView with cool animations. Use any image as annotation view.

MapViewPlus About MapViewPlus gives you the missing methods of MapKit which are: imageForAnnotation and calloutViewForAnnotationView delegate methods.

A fast, convenient and nonintrusive conversion framework between JSON and model. Your model class doesn't need to extend any base class. You don't need to modify any model file.

MJExtension A fast, convenient and nonintrusive conversion framework between JSON and model. 转换速度快、使用简单方便的字典转模型框架 📜 ✍🏻Release Notes: more details Co

Automate box any value! Print log without any format control symbol! Change debug habit thoroughly!

LxDBAnything Automate box any value! Print log without any format control symbol! Change debug habit thoroughly! Installation You only need drag LxD

Easily generate cross platform Swift framework projects from the command line
Easily generate cross platform Swift framework projects from the command line

SwiftPlate Easily generate cross platform Swift framework projects from the command line. SwiftPlate will generate Xcode projects for you in seconds,

👤 Framework to Generate Random Users - An Unofficial Swift SDK for randomuser.me
👤 Framework to Generate Random Users - An Unofficial Swift SDK for randomuser.me

RandomUserSwift is an easy to use Swift framework that provides the ability to generate random users and their accompanying data for your Swift applic

macOS app to generate Swift 5 code for models from JSON (with Codeable)
macOS app to generate Swift 5 code for models from JSON (with Codeable)

SwiftyJSONAccelerator - MacOS app Codeable Model file Generator For Swift 5 Version v2.2 Generate initializer function for classes Application Downloa

Generate Markdown documentation from source code
Generate Markdown documentation from source code

SourceDocs SourceDocs is a command line tool that generates markdown documentation files from inline source code comments. Similar to Sphinx or Jazzy,

Comments
  • Create a convenience method that increments an Int value

    Create a convenience method that increments an Int value

    User Story:

    As a consuming Developer, I want a clean, convenient way to increment Int values since this is a very common use case for badges

    Summary:

    Create a method that converts the badge's text value to an integer and increments it by n

    ex:

    /// convert `text` (`String`) to `Int` and increment by `num`
    func incrementValue(by num: Int)
    

    User Requirements

    • A single method (can be composed of multiple private methods if needed) that the Developer can call in order to increment a value by n

    Technical Requirements

    • Implement a Unit Test that proves the value increments by n

    Helpful Resources

    enhancement good first issue 
    opened by froggomad 1
  • Preview Provider Example & Usage Screenshots

    Preview Provider Example & Usage Screenshots

    User Story: As a user I want a quick way to preview the library before usage

    Summary: I have included a Preview Provider to make it easy for users to play with the library

    User Requirements

    • added preview provider
    • updated Example Badges description and screenshot

    Technical Requirements

    • Version 13.0 beta (13A5155e)

    Helpful Resources

    opened by codebendr-product-designer 0
Releases(0.0.4)
Owner
Kenny Dubroff (froggomad)
Full Stack iOS Developer: Swift, PHP, CSS, HTML, Javascript, node.js, AWS, Firebase
Kenny Dubroff (froggomad)
UIView extension that adds a notification badge.

Installation CocoaPods pod 'EasyNotificationBadge' Swift Package Manager You can use The Swift Package Manager to install EasyNotificationBadge by add

Antonio Zaitoun 215 Dec 11, 2022
iOS custom badge button.

MIBadgeButton MIBadgeButton is badge button written in Swift with high UITableView/UICollectionView performance. Screenshots Installation MIBadgeButto

Mustafa Ibrahim 344 Dec 28, 2022
A badge view for iOS/tvOS written in Swift

A badge control for iOS and tvOS written in Swift The badge is a subclass of UILabel view. It can be created and customized from the Storyboard or fro

Evgenii Neumerzhitckii 386 Dec 30, 2022
A way to quickly add a notification badge icon to any view. Make any view of a full-fledged animated notification center.

BadgeHub A way to quickly add a notification badge icon to any view. Demo/Example For demo: $ pod try BadgeHub To run the example project, clone the r

Jogendra 772 Dec 28, 2022
A way to quickly add a notification badge icon to any view. Make any view of a full-fledged animated notification center.

BadgeHub A way to quickly add a notification badge icon to any view. Demo/Example For demo: $ pod try BadgeHub To run the example project, clone the r

Jogendra 773 Dec 30, 2022
UIView extension that adds a notification badge.

Installation CocoaPods pod 'EasyNotificationBadge' Swift Package Manager You can use The Swift Package Manager to install EasyNotificationBadge by add

Antonio Zaitoun 215 Dec 11, 2022
UIView+CameraBackground - Show camera layer as a background to any UIView.

UIView+CameraBackground Show camera layer as a background to any UIView. Features Both front and back camera supported. Flash modes: auto, on, off. Co

Yonat Sharon 63 Nov 15, 2022
iOS custom badge button.

MIBadgeButton MIBadgeButton is badge button written in Swift with high UITableView/UICollectionView performance. Screenshots Installation MIBadgeButto

Mustafa Ibrahim 344 Dec 28, 2022
A badge view for iOS/tvOS written in Swift

A badge control for iOS and tvOS written in Swift The badge is a subclass of UILabel view. It can be created and customized from the Storyboard or fro

Evgenii Neumerzhitckii 386 Dec 30, 2022
TextDrawer, is a UIView allows you to add text, with gesture, on UIView, or UIImage

TextDrawer TextDrawer, is a UIView allows you to add text, with gesture, on UIView, or UIImage. About Annotating Images TextDrawer is the easiest way

Remi ROBERT 106 Dec 18, 2022