18

GitHub - jogendra/BadgeHub: A way to quickly add a notification badge icon to an...

 4 years ago
source link: https://github.com/jogendra/BadgeHub
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md

BadgeHub

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

52379966-080a5f00-2a92-11e9-8c85-9c34fabd4641.png

CI Status Version License Platform Donate

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

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

mix

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

Don't forget to import BadgeHub

Customization

Change the color of the notification circle

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 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 Bedge)

hideCount

hub.hideCount()

Show count again on the bedge

showCount

hub.showCount()

Animations

Pop out and pop in the bedge

Pop

hub.pop()

Make bedge blinking

Blink

hub.blink()

Animation that jumps similar to OSX 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.

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

Author

20956124?s=400&u=01fab3fc9bb3d2ee799e314d3fe23c54d1deeb07&v=4

Jogendra Kumar

687474703a2f2f7777772e69636f6e6e696e6a612e636f6d2f66696c65732f3234312f3832352f3231312f726f756e642d636f6c6c61626f726174696f6e2d736f6369616c2d6769746875622d636f64652d636972636c652d6e6574776f726b2d69636f6e2e737667 68747470733a2f2f7777772e736861726569636f6e2e6e65742f646f776e6c6f61642f323031362f30372f30362f3130373131355f6d656469612e737667 687474703a2f2f7777772e69636f6e6e696e6a612e636f6d2f66696c65732f3836332f3630372f3735312f6e6574776f726b2d6c696e6b6564696e2d736f6369616c2d636f6e6e656374696f6e2d63697263756c61722d636972636c652d6d656469612d69636f6e2e737667

License

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


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK