Swift Package Manager
You can use The Swift Package Manager to install
EasyNotificationBadge by adding the proper description to your
// 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"), ] )
swift build whenever you're ready.
Or simply drag and drop
NSBadge.swift to your project.
To add a badge with default settings use this (This also applies to updating an existing badge):
To remove the badge:
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)
.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.
You may find interesting
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