A way to quickly add a notification badge icon to any view. Make any view of a full-fledged animated notification center.

Overview

BadgeHub

A way to quickly add a notification badge icon to any view.

Version License Platform

Blink Bump Pop Custom setCircle showCount mix hideCount

Demo/Example

For demo:

$ pod try BadgeHub

To run the example project, clone the repo, and run pod install from the Example directory first.

$ cd Example
$ pod install

If you don't have CocoaPods installed, grab it with [sudo] gem install cocoapods.

$ open BadgeHub.xcworkspace

Requirements

  • iOS 10.0 or later
  • Swift 5+
  • Xcode 10+

Installation

CocoaPods

BadgeHub is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'BadgeHub'

Manual Installation

Just drag the BadgeHub.swift files into your project.

Usage

Initialization.

let hub = BadgeHub(view: yourView) // Initially count set to 0

Initializer for setting badge to bar button items.

let hub = BadgeHub(barButtonItem: UIBarButtonItem)

Increase count value by 1.

hub.increment()

Increase count by some int value.

hub.increment(by: Int)

Decrease count value by 1.

hub.decrement()

Decrease count by some int value.

hub.decrement(by: Int)

Set count to static integer value.

hub.setCount(newCount: Int)

Get value of current count on badge.

hub.getCurrentCount() // returns Int value of current count.

Combine actions

mix

hub.increment()
hub.pop()
hub.blink()

Don't forget to import BadgeHub

Customization

Change the color of the notification circle, also the text color of count label.

setCircleColor

hub.setCircleColor(_ circleColor: UIColor?, label labelColor: UIColor?)

Change the border color and border width of the circle

Custom

hub.setCircleBorderColor(_ color: UIColor?, borderWidth width: CGFloat)

Set the frame of the notification badge circle relative to the view.

setCircle

hub.setCircleAtFrame(_ frame: CGRect)

Move the circle (left/right or up/down).

hub.moveCircleBy(x: CGFloat, y: CGFloat)

Changes the size of the circle. setting a scale of 1 has no effect.

hub.scaleCircleSize(by scale: CGFloat)

Hide the count (Blank Badge). Keep in mind that this method is for hiding just count, not the badge.

hideCount

hub.hideCount()

Show count again on the badge.

showCount

hub.showCount()

Hide the badge from your view.

hub.hide()

Show again the badge. Badge will staye hidden even after calling this method, if current count on badge is <= 0.

hub.show()

Set max count which can be displayed. This method can be used to restrict the maximum count can be set on the badge. Default value for max count is 100000. If you increase current count to more than max count, badge will display it like 500+ (if max count is 500).

hub.setMaxCount(to: Int)

Set the font of the count label.

hub.setCountLabelFont(_ font: UIFont?)

Get the current font set on the count label.

hub.getCountLabelFont()

Set alpha to badge.

hub.setAlpha(alpha: CGFloat)

Animations

Pop out and pop in the badge.

Pop

hub.pop()

Make badge blinking.

Blink

hub.blink()

Animation that jumps similar to macOS dock icons.

Bump

hub.bump()

TROUBLESHOOTING

Notification isn't showing up!

  • If the hub value is < 1, the circle hides. Try calling increment().
  • Make sure the view you set the hub to is visible (i.e. did you call self.view.addSubview(yourView)?).
  • Make sure you didn't call hideCount() anywhere. Call showCount() to counter this.

Badge is not hiding even after setting value to 0

  • Make sure you are setting zero count on correct BadgeHub instance.
  • Try calling checkZero() method after setting count to 0.
  • Varify if current count is <= 0 by calling getCurrentCount() method.
  • Keep in mind that hideCount() method is for hiding just count, not the badge. To hide the badge, simply call hide().

It isn't incrementing / decrementing properly!

  • Any count < 1 doesn't show up. If you need help customizing this, reach out to me!

The circle is in a weird place

  • If you want to resize the circle, use scaleCircleSize(by scale: CGFloat). 0.5 will give you half the size, 2 will give you double.
  • If the circle is just a few pixels off, use moveCircleBy(x: CGFloat, y: CGFloat). This shifts the circle by the number of pixels given.
  • If you want to manually set the circle, call setCircleAtFrame(_ frame: CGRect) and give it your own CGRect.

Something else isn't working properly

  • Use GitHub's issue reporter to submit a new issue.
  • If you think you fix that, feel free to open a pull request fixing the same.
  • Shoot me an email at [email protected].

Author

Jogendra Kumar

License

BadgeHub is available under the MIT license. See the LICENSE file for more info.

Comments
  • Badge hiding behind view.

    Badge hiding behind view.

    I am trying to append badgehub onto a UIImageView. The badge is appearing however when it reaches the corner; it stays behind the imageview or view and just hides away.

    I tried setting the z-index however that doesn't seem to be affecting anything. Anyone else having this issue? Or found a solution. Cheers

    let hub = BadgeHub(view: cell.contentView) // Initially count set to 0
    hub.hubView?.layer.zPosition = 10000
    hub.increment()
    
    good first issue Hacktoberfest hacktoberfest-accepted 
    opened by Harryjeffs 6
  • Fixing implied internals

    Fixing implied internals

    Fixes the following:

    • #6 (Initializer not specifically marked public)
    • Several methods that were implicitly interpreted as internal

    Also bumps podspec to 0.1.1

    Note to @jogendra: anything not explicitly marked public or private is interpreted by the compiler as internal :)

    opened by MatrixSenpai 4
  • SetCount to 0 and checkZero not removing red dot

    SetCount to 0 and checkZero not removing red dot

    When setting my count to 0 the red dot stays as 1 and does not disappear.

    I have tried to call checkZero( ), decrement the count from one to zero instead of set to zero, and even refresh the views but nothing has worked.

    Is there a way to remove the hub from the view it is attached to? I looked around for removing subviews from views but I could not find anything.

    badgehub screen shot.pdf

    good first issue Hacktoberfest hacktoberfest-accepted 
    opened by JakeEllis 1
  • maxCount is not taken into account when calling the increment method

    maxCount is not taken into account when calling the increment method

    Hello everybody!

    I've found out that maxCount is taken into account only when we call the setCount method, unfortunately, this constant doesn't apply for calls of increment. Example:

    hub.setMaxCount(99)
    hub.increment(by: 150)
    // count == 150
    

    Compare their implementations to each other. increment:

        /// Increases count by 1
        public func increment() {
            increment(by: 1)
        }
        
        /// Increases count by amount.
        /// - Parameter amount: Increment count.
        public func increment(by amount: Int) {
            count += amount
        }
    

    setCount:

        /// Set the count yourself.
        /// - Parameter newCount: New count to be set to badge.
        public func setCount(_ newCount: Int) {
            self.count = newCount
            let labelText = count > maxCount ? "\(maxCount)+" : "\(count)"
            countLabel?.text = labelText
            checkZero()
        }
    
    opened by oleg-samoylov-ext-orion 0
  • Hide Count hiding wrong object?

    Hide Count hiding wrong object?

    Shouldn't Hide Count hide the label and not the badge? (it currently hides the badge and leaves the number)

    /// Hide the count (Blank Badge). /// Remember this only hide count, /// and not the red dot. public func hideCount() { countLabel?.isHidden = true }

    opened by justdan0227 0
  • UITableViewCell

    UITableViewCell

    how to you set the badge to be upper left corner in the text of a UITableViewCell.textLabel ? I tried setCircleAtFrame and it shows up left but cut off and when I scroll then it shows up left and a second one on the right? With dequeue do I have to do something to use it in a UITableViewCell?

    opened by justdan0227 2
  • init?(barButtonItem: UIBarButtonItem) create nil BadgeHub

    init?(barButtonItem: UIBarButtonItem) create nil BadgeHub

    When the barButtonItem create by storyboard, init?(barButtonItem: UIBarButtonItem) create not nil BadgeHub.

    But when the barButtonItem create by code in viewDidLoad function, init?(barButtonItem: UIBarButtonItem) create a nil BadgeHub, but barButtonItem is not nil.

        let hub = BadgeHub(barButtonItem: testItem)
        hub?.increment()
        
        let leftItem = UIBarButtonItem(title: "Badge", style: .plain, target: self, action: nil)
        navigationItem.leftBarButtonItem = leftItem
        
        let itemHub = BadgeHub(barButtonItem: leftItem)
        itemHub?.increment(by: 10)
    

    hub create by Storyboard's UIBarButtonItem ,itemHub create by code UIBarButtonItem: leftItem

    hub is not nil, itemHub is nil

    opened by pekanchuan 2
Releases(1.0.0)
Owner
Jogendra
iOS / Backend Engineer | Aviation | Go | Swift | GSoC '18 | IIT BHU'20
Jogendra
Generate a badge for any UIView

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 light

Kenny Dubroff (froggomad) 11 Jan 6, 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
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 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
LoadingButtton - Add button extendded from LoadingButton in the view and make it center horizontally

LoadingButtton Usage/Examples Add button extendded from LoadingButton in the vie

Alireza 1 Jan 8, 2022
This app is a sample app that recognizes specific voice commands such as "make it red", "make it blue", "make it green", and "make it black" and change the background color of the view in the frame.

VoiceOperationSample This app is a sample app that recognizes specific voice commands such as "make it red", "make it blue", "make it green", and "mak

Takuya Aso 3 Dec 3, 2021
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
Icons fonts for iOS (Font Awesome 5, Iconic, Ionicon, Octicon, Themify, MapIcon, MaterialIcon, Foundation 3, Elegant Icon, Captain Icon)

Installation SPM Not yet supported. Please use Cocoapods or Carthage Carthage github "0x73/SwiftIconFont" Cocoapods CocoaPods is a dependency manager

sedat çiftçi 1.1k Dec 14, 2022
IconChanger - an app that can change you app's icon. It simplifies your icon changing process

IconChanger IconChanger is an app that can change you app's icon. It simplifies your icon changing process. How to use Go to github release Download t

Underthestars-zhy 561 Jan 5, 2023
This is a command line tool to extract an app icon. this sample will extract the icon 16x16 from Safari app.

?? X-BundleIcon This is a command line tool to extract an app icon. this sample will extract the icon 16x16 from Safari app. xbi com.apple.Safari 16 /

Rui Aureliano 3 Sep 1, 2022
Generate a badge for any UIView

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 light

Kenny Dubroff (froggomad) 11 Jan 6, 2022
A fully fledged syscfg editor. Just the editor. Written in pure swift.

MagicCFG Reloaded The SysCFG Writing Utility - UPDATED, OSV Report Bug Table of Contents About MagicCFG Reloaded Getting Started Roadmap Contact Credi

Jan Fabel 47 Dec 31, 2022
SwiftySideMenu is a lightweight and easy to use side menu controller to add left menu and center view controllers with scale animation based on Pop framework.

SwiftySideMenu SwiftySideMenu is a lightweight, fully customizable, and easy to use controller to add left menu and center view controllers with scale

Hossam Ghareeb 84 Feb 4, 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
Roar - Let's reskin Notification Center

Roar Let's reskin Notification Center. See this blog post. Thanks Big thanks to

Tyler Hall 8 Mar 15, 2022
Make your notification banners smaller and add some color to them

Liddell Liddell notification banners Installation Add this repository to your Package Manager: https://repo.litten.love Install Liddell Compiling Depe

alexandra 34 Dec 22, 2022
This to learn such as : Add Target , NSNotification Center Send/Get Data , Observer Override , resize Data By Byte , UIImagePicker Delegate , UIAlert Handle , Top ViewController , Get pickerController

Technicalisto How to Create UIButton Class to Pick Data Image Purpose Learn this topics With exact Task Add Target NSNotification Center Send/Get Data

Aya Baghdadi 1 Feb 20, 2022
Let's put notification Messages icon on menu bar of your macOS

DockBar DockBar is just a simple app that show messages icon on your status bar when you have unread messages. This app is very useful for people who

Bastard.y 5 Aug 16, 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
Library for iOS Camera API. CameraKit helps you add reliable camera to your app quickly.

CameraKit helps you add reliable camera to your app quickly. Our open source camera platform provides consistent capture results, service that scales, and endless camera possibilities.

CameraKit 628 Dec 27, 2022