• Stars
    star
    809
  • Rank 56,370 (Top 2 %)
  • Language
    Swift
  • License
    MIT License
  • Created almost 6 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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.

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.

More Repositories

1

LoadingShimmer

An easy way to add a shimmering effect to any view with just one line of code. It is useful as an unobtrusive loading indicator.
Swift
1,528
star
2

example-ios-apps

ο£Ώ A curated list of Open Source example iOS apps developed in Swift. An amazing list for people who are beginners and learning ios development and for ios developers who need any example app or feature.
Swift
814
star
3

phimpme-iOS

Phimp.me - Photo Image Editor and Sharing App. Phimp.me is a Photo App for iOS that aims to replace proprietary photo applications. It offers features such as taking photos, adding filters, editing images and uploading them to social networks.
Swift
119
star
4

dotfiles

Config files for zsh, bash, vim, git, completions etc. to set up a system the way I like it. ~/.jogendra
Shell
66
star
5

ds-algo-placement-resources

A complete roadmap and resources for competitive programming for placement purpose.
Swift
59
star
6

DS-Algo-Interview-Questions

Collection of some important questions asked in job interviews.
C++
41
star
7

HealthLedger

Application for tracking Organs donations in hospitals and minimizing the scope of Organ trafficking using Blockchain (Hyperledger) technology.
CSS
35
star
8

launch-at-login-macos

An example project demonstrating Launch at Login (launch application on system startup) feature implementation for macOS Apps in Swift.
Swift
24
star
9

AnimatedMaskLabel

Animated Mask Label is a nice gradient animated label. This is an easy way to add a shimmering effect to any view in your app. It is useful as an unobtrusive loading indicator.
Swift
21
star
10

material-navigation-bar

Custom UINavigationBar with Google Material style for iOS, with very smooth animations
Swift
20
star
11

OpenTender

E-portal for government tender process using Hyperledger (Blockchain) technology.
JavaScript
20
star
12

Wheelstreet-GO

iOS App for Wheelstreet GO. I worked on this app during my Winter 2018 iOS Developer Internship at WheelStreet Inc.
Swift
20
star
13

Calculator-iOS

Basic calculator app for iOS devices using Swift3. Created for learning purpose.
Swift
18
star
14

todolist-ios-app

Basic 'To Do List' App for iOS devices using swift and xcode!
Swift
17
star
15

Social-Logins-iOS

Basic app to show how to login with Facebook, Google, Twitter. Created for learning purpose :) using Xcode 9 and Swift 4.0
Swift
15
star
16

JSButton

A fully customisable swift subclass on UIButton which allows you to create beautiful buttons without writing any line of code.
Swift
12
star
17

technex-ios

iOS app for Technex, IIT(BHU) Varanasi. This project is closed before completion. You can use this app for learning purpose. You can use this app as a templet of any event related app.
Swift
12
star
18

import-cycle-example-go

A simple example showing Import Cycle in Golang and how to deal with them.
Go
8
star
19

my-old-personal-website

[OLD] My Portfolio - Personal blogs, Projects.
CSS
7
star
20

farmers-bank

Application for selling and buying crops for farmers using HyperLedger technology.
CSS
7
star
21

jogendra.github.io

Source code of my personal portfolio
SCSS
7
star
22

ChartKit-Swift

Beautiful Chart library for iOS written in Swift 4.2. Bar Chart, Clock Chart and Contribution Graph. Supports Storyboard.
Objective-C
7
star
23

gravityBlocks

A basic iOS app on basic physics concept gravity and elasticity.
Swift
6
star
24

stopwatch

Basic Stop Watch & Countdown app for iOS devices. Created for learning purpose.
Swift
6
star
25

JSLabel

A simple designable subclass on UILabel with extra IBDesignable and Blinking features.
Swift
6
star
26

FireMessenger-Android

Real time chat app for Android, developed in Kotlin. Used Google Firebase for Auth and Database.
Kotlin
5
star
27

Raindrop-CLI

CLI client for Raindrop.io written in Go
Go
4
star
28

spardha17-iitbhu

Official website for Spardha 2017.
CSS
4
star
29

blubyn-ios

This repository contains iOS version on Blubyn App.
Swift
3
star
30

StatusView

Show actionable messages on top of the status bar with full customizable colors, font and animation. It appear below the top status bar and appears like the message is embedded within.
Swift
3
star
31

bookmark-cli

CLI application to manage bookmarks.
Go
3
star
32

awesome-ios-developers

An awesome list of iOS Developers who is active in Open Source community
Swift
3
star
33

JSSideBar

Customisable Android like Side Bar for iOS.
Swift
3
star
34

Landmark-SwiftUI-TutorialApp

Apple's new SwiftUI tutorial for an iOS app for discovering and sharing the places you love.
Swift
3
star
35

kite-cli

Command line client for stock market investment and trading using Zerodha's Kite Connect APIs.
Go
2
star
36

example

2
star
37

mun-iitbhu

Official website for MUN 2017, IIT(BHU), Varanasi
HTML
2
star
38

sudoku-solver-ios

Sudoku solver app for iOS
Swift
1
star
39

JSDesignable

Extended Inspectable classes for ios UI Elements.
Swift
1
star
40

example-repo

1
star
41

jigyasa17

Official website for Jigyasa 2017.
JavaScript
1
star
42

XcodePlaygrounds

Just a bunch of Xcode Playgrounds created for learning purpose!
Swift
1
star
43

DogListings

Simple example app for learning purpose
Swift
1
star
44

start-with-open-source

All the resources you need for starting with Open Source and Version control system Git.
1
star
45

test

HTML
1
star
46

chemistry-iitbhu

Official website for Department of Chemistry, IIT(BHU) Varanasi.
HTML
1
star
47

JSBlurrySidebar

A beautiful customized blurry side bar for ios.
Shell
1
star
48

jogendra

1
star
49

youtube-clone

Basic YouTube home page clone with player embded. Created for learning purpose.
HTML
1
star
50

lawbhu-website

Website for Faculty of Law, Banaras Hindu University, Varanasi
HTML
1
star
51

BookStore

A simple REST API written in Go for book store for learning purpose
Go
1
star
52

creative-workline-ios-test

iOS Developer Summer Internship Test Project for Creative Workline.
Swift
1
star
53

moss-go

Go version of submission script for MOSS (Measure Of Software Similarity): Plagiarism detection service
1
star
54

ShoppingApp-iOS

Basic shopping app with functionality of Remote and Core Data.
Swift
1
star