A way to quickly add a notification badge icon to any view
BadgeHub
A way to quickly add a notification badge icon to any view. Make any UIView a full fledged animated notification center.
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
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)
Combine actions
hub.increment()
hub.pop()
hub.blink()
Don't forget to import BadgeHub
Customization
Change the color of the notification circle
hub.setCircleColor(_ circleColor: UIColor?, label labelColor: UIColor?)
Change the border color and border width of the circle
hub.setCircleBorderColor(_ color: UIColor?, borderWidth width: CGFloat)
Set the frame of the notification circle relative to the view
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 Bedge)
hub.hideCount()
Show count again on the bedge
hub.showCount()
Animations
Pop out and pop in the bedge
hub.pop()
Make bedge blinking
hub.blink()
Animation that jumps similar to OSX dock icons
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. CallshowCount()
to counter this.
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 on the right.
- Send me an email jogendra.iitbhu@gmail.com