Swiftpack.co - Package - Minitour/EasyNotificationBadge

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.0"),
    ]
)

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 0
badgeAppearance.distanceFromCenterY = -10 //default is 0
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.

Credit

Some of the code that was used in this extension was originally written by mustafaibrahim989 in the library MIBadgeButton-Swift.

Github

link
Stars: 203

Dependencies

Used By

Total: 0

Releases

Swift 4.2 release - 2018-10-02 16:44:28

Version 1.1.3 - 2017-11-23 11:37:53

  • Fixed bug of badge appearing under icons and labels in UIBarButtonItems.
  • Enhanced code
  • Renamed source file to EasyNotificationBadge.swift

Swift 4.0 Release - 2017-11-03 16:10:32

Small fixes and improvments - 2017-11-03 16:03:41

Added animation when updating existing text on a badge.

Swift 4.0 Support - 2017-10-24 09:24:10

v1.0.3 Release - 2017-02-01 17:28:02

  • Improved animation.
  • Fixed bug that causes crash when adding a badge for a UITabBarItem that was not loaded.

More customization support - 2017-01-15 09:40:57

  • Shadow support
  • Border support

- 2017-01-07 21:39:45