UIView extension that adds a notification badge.

Overview

CocoaPods CocoaPods CocoaPods

Installation

CocoaPods

pod 'EasyNotificationBadge'

Swift Package Manager

You can use The Swift Package Manager to install EasyNotificationBadge by adding the proper description to your Package.swift file:

// swift-tools-version:4.0
import PackageDescription

let package = Package(
    name: "YOUR_PROJECT_NAME",
    dependencies: [
        .package(url: "https://github.com/Minitour/EasyNotificationBadge.git", from: "1.2.4"),
    ]
)

Then run swift build whenever you're ready.

Or simply drag and drop NSBadge.swift to your project.

Usage

To add a badge with default settings use this (This also applies to updating an existing badge):

view.badge(text: "5")

To remove the badge:

view.badge(text: nil)

Advanced Usage

var badgeAppearance = BadgeAppearance()
badgeAppearance.backgroundColor = UIColor.blue //default is red
badgeAppearance.textColor = UIColor.white // default is white
badgeAppearance.textAlignment = .center //default is center
badgeAppearance.textSize = 15 //default is 12
badgeAppearance.distanceFromCenterX = 15 //default is nil
badgeAppearance.distanceFromCenterY = -10 //default is nil
badgeAppearance.allowShadow = true
badgeAppearance.borderColor = .blue
badgeAppearance.borderWidth = 1
view.badge(text: "Your text", appearance: badgeAppearance)

Important

When calling .badge make sure that the view has already been loaded and has a superview. Setting a badge on a view that hasn't fully loaded can lead to unexpected results.

Comments
  • Getting crash

    Getting crash

    I was using it for add badge on barbuttonitem . but its not working I am getting crash on the fatal error: unexpectedly found nil while unwrapping an Optional value

    opened by Raviojha62 6
  • Badge's views appearing below.

    Badge's views appearing below.

    Badges appear correctly first time.

    However, the problem happens when you return from a pushed UIViewController from NavigationViewController.

    screen shot 2017-11-22 at 4 24 38 pm

    Only happens in devices running iOS 11 [Xcode 9.1].

    Thank you for the library 😁

    opened by lukeleleh 5
  • Add Swift Version to Podspec

    Add Swift Version to Podspec

    • The Podspec is missing the swift version. I believe this project was built using Swift 5 but if the version is incorrect, let me know and I will update the PR!
    opened by DomenicBianchi01 3
  • Unable to set CenterX and CenterY to 0

    Unable to set CenterX and CenterY to 0

    It is not possible to set the centerY (and centerX) offsets to 0. The following code prevents this. However 0 is a valid value to center align precisely.

     //The distance from the center of the view (vertically)
    let centerY = appearance.distanceFromCenterY == 0 ? -(bounds.size.height / 2) : appearance.distanceFromCenterY
    
     //The distance from the center of the view (horizontally)
    let centerX = appearance.distanceFromCenterX == 0 ? (bounds.size.width / 2) : appearance.distanceFromCenterX
    

    A workaround is to set distanceFromCenterY or distanceFromCenterX to a very small non zero value such as 0.01 but it feels yucky!

    opened by chamitha 2
  • UIBarButtonItem badge

    UIBarButtonItem badge

    Description I've tried to set badge to UIBarButtonItem but badge is not visible.

    Code I've used

    let filterButton = UIBarButtonItem(image: #imageLiteral(resourceName: "filter"),
    								   style: .plain,
    								   target: self,
    								   action: nil)
    filterButton.tintColor = .primary
    filterButton.badge(text: "2")
    

    image


    Workaround Instead of creating UIBarButtonItem with image create it using customView constructor

    let filterButton = UIBarButtonItem(customView: UIImageView(image: #imageLiteral(resourceName: "filter")))
    filterButton.tintColor = .primary
    filterButton.action = #selector(filter(_:))
    filterButton.customView?.badge(text: "2")
    navigationItem.rightBarButtonItem = filterButton
    

    Thanks for great lightweight library.

    Best regards, Najdan

    opened by Najdan 2
  • Fix typos and add @objc annotations

    Fix typos and add @objc annotations

    Fixes two typos:

    1. appearnce -> appearance
    2. distence -> distance

    I also took the liberty to do some code formatting using swiftlint autocorrect, update the example project and remove some dead code.

    Bumped version to 1.1.0 since these are breaking changes (the typos are in the method signatures).

    opened by gigi-mohemian 1
  • SPM Integration

    SPM Integration

    1. Implemented Swift Package Management.
    2. Moved Sources files to Sources/EasyNotificationBadge/
    3. Reconfigured the example app so it works with the SPM.
    4. Moving the example app to EasyNotificationBadgeExample/
    5. Updated Example app to Swift 5.
    6. Fixed warnings.
    7. Updating README.md to include SPM Instructions.
    opened by afnanm1999 0
  • Value of type 'BadgeAppearance' has no member 'textSize'

    Value of type 'BadgeAppearance' has no member 'textSize'

    Updated podfile from: pod 'Koloda', '-> 4.3.1' to: pod "Koloda"

    After that badgeAppearance.textSize = 14 gives the follow message: "Value of type 'BadgeAppearance' has no member 'textSize'".

    Downloaded GitHub repository and tested example project and got same behavior.

    Was the removal of textSize property intended?

    opened by ElyDantas 0
Releases(1.2.5)
Owner
Antonio Zaitoun
24, Mobile Dev & System architect. Software Engineer at GE Healthcare. Information Systems B.Sc. Graduate and M.Sc. student at University of Haifa.
Antonio Zaitoun
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
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
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
UIView and CGRect extension that adds properties to manipulate them efficiently

Geometry Geometry is a UIView and CGRect extension that lets you work with view and rect geometry easier. It adds the following properties to UIView:

Tuomas Artman 92 Sep 7, 2022
A Swift extension that adds toast notifications to the UIView object class.

Toast-Swift Toast-Swift is a Swift extension that adds toast notifications to the UIView object class. It is intended to be simple, lightweight, and e

Charles Scalesse 3.3k Dec 22, 2022
UIView extension that adds dragging capabilities

YiViewDrag Installation YiViewDrag is available through CocoaPods. To install it, simply add the following line to your Podfile: pod 'YiViewDrag' Usag

coderyi 1 Jan 20, 2022
An example implementation of using a native iOS Notification Service Extension (to display images in remote push notification) in Titanium.

Titanium iOS Notification Service Extension An example implementation of using a native iOS Notification Service Extension (to display images in remot

Hans Knöchel 8 Nov 21, 2022
UIView category that adds shake animation

UIView category that adds a shake animation like the password field of the OSX login screen. Screenshot Setup with CocoaPods Add pod 'UIView+Shake' to

Andrea Mazzini 498 Nov 20, 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
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

null 169 Aug 14, 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
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
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

Justin Cook 3 Aug 4, 2022
UITextField extension in Swift that adds shake animation

UITextField-Shake-Swift UITextField extension in Swift that adds shake animation Initially created by Andrea Mazzini (using Objective-C) on 08/02/14:

null 15 Jul 20, 2021
This is an iOS Safari Extension Sample that adds a "Develop menu" to Safari on iOS to allow you to analyze websites.

Develop Menu for Mobile Safari This is an iOS Safari Extension that adds a "Develop menu" to Safari on iOS to allow you to analyze websites. This is a

Watanabe Toshinori 1 Dec 7, 2022
Swift extension which adds start, animating and completion closures for CAAnimation objects. Aka, CAAnimation + Closure / Block

Swift-CAAnimation-Closure Swift extension which adds start, animating and completion closures for CAAnimation objects. Aka, CAAnimation + Closure or C

HongHao Zhang 112 Jun 17, 2022