├── .gitignore
├── EasyNotificationBadge.podspec
├── Example
├── EasyNotificationBadgeExample.xcworkspace
│ └── contents.xcworkspacedata
├── NotificationBadgeExample.xcodeproj
│ ├── project.pbxproj
│ └── project.xcworkspace
│ │ └── contents.xcworkspacedata
└── NotificationBadgeExample
│ ├── AppDelegate.swift
│ ├── Assets.xcassets
│ └── AppIcon.appiconset
│ │ └── Contents.json
│ ├── Base.lproj
│ ├── LaunchScreen.storyboard
│ └── Main.storyboard
│ ├── Info.plist
│ └── ViewController.swift
├── LICENSE
├── Package.swift
├── README.md
├── Screenshots
├── .DS_Store
├── heading.gif
├── ss1.png
├── ss2.png
├── ss3.png
├── ss4.png
├── ss5.png
└── ss6.PNG
└── Sources
└── EasyNotificationBadge
└── EasyNotificationBadge.swift
/.gitignore:
--------------------------------------------------------------------------------
1 | # Xcode
2 | #
3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
4 |
5 | ## Build generated
6 | build/
7 | DerivedData/
8 |
9 | ## Various settings
10 | *.pbxuser
11 | !default.pbxuser
12 | *.mode1v3
13 | !default.mode1v3
14 | *.mode2v3
15 | !default.mode2v3
16 | *.perspectivev3
17 | !default.perspectivev3
18 | xcuserdata/
19 |
20 | ## Other
21 | *.moved-aside
22 | *.xcuserstate
23 |
24 | ## Obj-C/Swift specific
25 | *.hmap
26 | *.ipa
27 | *.dSYM.zip
28 | *.dSYM
29 |
30 | ## Playgrounds
31 | timeline.xctimeline
32 | playground.xcworkspace
33 |
34 | # Swift Package Manager
35 | #
36 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
37 | # Packages/
38 | .build/
39 |
40 | # CocoaPods
41 | #
42 | # We recommend against adding the Pods directory to your .gitignore. However
43 | # you should judge for yourself, the pros and cons are mentioned at:
44 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
45 | #
46 | # Pods/
47 |
48 | # Carthage
49 | #
50 | # Add this line if you want to avoid checking in source code from Carthage dependencies.
51 | # Carthage/Checkouts
52 |
53 | Carthage/Build
54 |
55 | # fastlane
56 | #
57 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
58 | # screenshots whenever they are needed.
59 | # For more information about the recommended setup visit:
60 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md
61 |
62 | fastlane/report.xml
63 | fastlane/Preview.html
64 | fastlane/screenshots
65 | fastlane/test_output
66 | .DS_Store
67 | .swiftpm
--------------------------------------------------------------------------------
/EasyNotificationBadge.podspec:
--------------------------------------------------------------------------------
1 | Pod::Spec.new do |s|
2 | s.name = "EasyNotificationBadge"
3 | s.version = "1.2.5"
4 | s.summary = "UIView extension that adds a notification badge."
5 | s.homepage = "https://github.com/Minitour/EasyNotificationBadge"
6 | s.license = "MIT"
7 | s.author = { "Antonio Zaitoun" => "tony.z.1711@gmail.com", "Christoph Gigi Fuchs" => "dergigi@gmail.com" }
8 | s.platform = :ios, "9.0"
9 | s.source = { :git => "https://github.com/Minitour/EasyNotificationBadge.git", :tag => "#{s.version}" }
10 | s.source_files = "Sources/**/*.swift"
11 | s.swift_version = '5.0'
12 | end
13 |
--------------------------------------------------------------------------------
/Example/EasyNotificationBadgeExample.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Example/NotificationBadgeExample.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 52;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 4F6C9B3E1D5C641D000098B8 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F6C9B3D1D5C641D000098B8 /* AppDelegate.swift */; };
11 | 4F6C9B401D5C641D000098B8 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F6C9B3F1D5C641D000098B8 /* ViewController.swift */; };
12 | 4F6C9B431D5C641D000098B8 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4F6C9B411D5C641D000098B8 /* Main.storyboard */; };
13 | 4F6C9B451D5C641D000098B8 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4F6C9B441D5C641D000098B8 /* Assets.xcassets */; };
14 | 4F6C9B481D5C641D000098B8 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4F6C9B461D5C641D000098B8 /* LaunchScreen.storyboard */; };
15 | CF778DE125383FDC00D71C25 /* EasyNotificationBadge in Frameworks */ = {isa = PBXBuildFile; productRef = CF778DE025383FDC00D71C25 /* EasyNotificationBadge */; };
16 | /* End PBXBuildFile section */
17 |
18 | /* Begin PBXFileReference section */
19 | 4F6C9B3A1D5C641D000098B8 /* NotificationBadgeExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NotificationBadgeExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
20 | 4F6C9B3D1D5C641D000098B8 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; };
21 | 4F6C9B3F1D5C641D000098B8 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; };
22 | 4F6C9B421D5C641D000098B8 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
23 | 4F6C9B441D5C641D000098B8 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
24 | 4F6C9B471D5C641D000098B8 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; };
25 | 4F6C9B491D5C641D000098B8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
26 | /* End PBXFileReference section */
27 |
28 | /* Begin PBXFrameworksBuildPhase section */
29 | 4F6C9B371D5C641D000098B8 /* Frameworks */ = {
30 | isa = PBXFrameworksBuildPhase;
31 | buildActionMask = 2147483647;
32 | files = (
33 | CF778DE125383FDC00D71C25 /* EasyNotificationBadge in Frameworks */,
34 | );
35 | runOnlyForDeploymentPostprocessing = 0;
36 | };
37 | /* End PBXFrameworksBuildPhase section */
38 |
39 | /* Begin PBXGroup section */
40 | 4F6C9B311D5C641D000098B8 = {
41 | isa = PBXGroup;
42 | children = (
43 | 4F6C9B3C1D5C641D000098B8 /* NotificationBadgeExample */,
44 | 4F6C9B3B1D5C641D000098B8 /* Products */,
45 | );
46 | sourceTree = "";
47 | };
48 | 4F6C9B3B1D5C641D000098B8 /* Products */ = {
49 | isa = PBXGroup;
50 | children = (
51 | 4F6C9B3A1D5C641D000098B8 /* NotificationBadgeExample.app */,
52 | );
53 | name = Products;
54 | sourceTree = "";
55 | };
56 | 4F6C9B3C1D5C641D000098B8 /* NotificationBadgeExample */ = {
57 | isa = PBXGroup;
58 | children = (
59 | 4F6C9B3D1D5C641D000098B8 /* AppDelegate.swift */,
60 | 4F6C9B3F1D5C641D000098B8 /* ViewController.swift */,
61 | 4F6C9B411D5C641D000098B8 /* Main.storyboard */,
62 | 4F6C9B441D5C641D000098B8 /* Assets.xcassets */,
63 | 4F6C9B461D5C641D000098B8 /* LaunchScreen.storyboard */,
64 | 4F6C9B491D5C641D000098B8 /* Info.plist */,
65 | );
66 | path = NotificationBadgeExample;
67 | sourceTree = "";
68 | };
69 | /* End PBXGroup section */
70 |
71 | /* Begin PBXNativeTarget section */
72 | 4F6C9B391D5C641D000098B8 /* NotificationBadgeExample */ = {
73 | isa = PBXNativeTarget;
74 | buildConfigurationList = 4F6C9B4C1D5C641D000098B8 /* Build configuration list for PBXNativeTarget "NotificationBadgeExample" */;
75 | buildPhases = (
76 | 4F6C9B361D5C641D000098B8 /* Sources */,
77 | 4F6C9B371D5C641D000098B8 /* Frameworks */,
78 | 4F6C9B381D5C641D000098B8 /* Resources */,
79 | );
80 | buildRules = (
81 | );
82 | dependencies = (
83 | );
84 | name = NotificationBadgeExample;
85 | packageProductDependencies = (
86 | CF778DE025383FDC00D71C25 /* EasyNotificationBadge */,
87 | );
88 | productName = NotificationBadgeExample;
89 | productReference = 4F6C9B3A1D5C641D000098B8 /* NotificationBadgeExample.app */;
90 | productType = "com.apple.product-type.application";
91 | };
92 | /* End PBXNativeTarget section */
93 |
94 | /* Begin PBXProject section */
95 | 4F6C9B321D5C641D000098B8 /* Project object */ = {
96 | isa = PBXProject;
97 | attributes = {
98 | LastSwiftUpdateCheck = 0800;
99 | LastUpgradeCheck = 0800;
100 | ORGANIZATIONNAME = "New Sound Interactive";
101 | TargetAttributes = {
102 | 4F6C9B391D5C641D000098B8 = {
103 | CreatedOnToolsVersion = 8.0;
104 | DevelopmentTeam = 35DWKWL79J;
105 | LastSwiftMigration = 1200;
106 | ProvisioningStyle = Automatic;
107 | };
108 | };
109 | };
110 | buildConfigurationList = 4F6C9B351D5C641D000098B8 /* Build configuration list for PBXProject "NotificationBadgeExample" */;
111 | compatibilityVersion = "Xcode 3.2";
112 | developmentRegion = English;
113 | hasScannedForEncodings = 0;
114 | knownRegions = (
115 | English,
116 | en,
117 | Base,
118 | );
119 | mainGroup = 4F6C9B311D5C641D000098B8;
120 | packageReferences = (
121 | CF778DDF25383FDC00D71C25 /* XCRemoteSwiftPackageReference "." */,
122 | );
123 | productRefGroup = 4F6C9B3B1D5C641D000098B8 /* Products */;
124 | projectDirPath = "";
125 | projectRoot = "";
126 | targets = (
127 | 4F6C9B391D5C641D000098B8 /* NotificationBadgeExample */,
128 | );
129 | };
130 | /* End PBXProject section */
131 |
132 | /* Begin PBXResourcesBuildPhase section */
133 | 4F6C9B381D5C641D000098B8 /* Resources */ = {
134 | isa = PBXResourcesBuildPhase;
135 | buildActionMask = 2147483647;
136 | files = (
137 | 4F6C9B481D5C641D000098B8 /* LaunchScreen.storyboard in Resources */,
138 | 4F6C9B451D5C641D000098B8 /* Assets.xcassets in Resources */,
139 | 4F6C9B431D5C641D000098B8 /* Main.storyboard in Resources */,
140 | );
141 | runOnlyForDeploymentPostprocessing = 0;
142 | };
143 | /* End PBXResourcesBuildPhase section */
144 |
145 | /* Begin PBXSourcesBuildPhase section */
146 | 4F6C9B361D5C641D000098B8 /* Sources */ = {
147 | isa = PBXSourcesBuildPhase;
148 | buildActionMask = 2147483647;
149 | files = (
150 | 4F6C9B401D5C641D000098B8 /* ViewController.swift in Sources */,
151 | 4F6C9B3E1D5C641D000098B8 /* AppDelegate.swift in Sources */,
152 | );
153 | runOnlyForDeploymentPostprocessing = 0;
154 | };
155 | /* End PBXSourcesBuildPhase section */
156 |
157 | /* Begin PBXVariantGroup section */
158 | 4F6C9B411D5C641D000098B8 /* Main.storyboard */ = {
159 | isa = PBXVariantGroup;
160 | children = (
161 | 4F6C9B421D5C641D000098B8 /* Base */,
162 | );
163 | name = Main.storyboard;
164 | sourceTree = "";
165 | };
166 | 4F6C9B461D5C641D000098B8 /* LaunchScreen.storyboard */ = {
167 | isa = PBXVariantGroup;
168 | children = (
169 | 4F6C9B471D5C641D000098B8 /* Base */,
170 | );
171 | name = LaunchScreen.storyboard;
172 | sourceTree = "";
173 | };
174 | /* End PBXVariantGroup section */
175 |
176 | /* Begin XCBuildConfiguration section */
177 | 4F6C9B4A1D5C641D000098B8 /* Debug */ = {
178 | isa = XCBuildConfiguration;
179 | buildSettings = {
180 | ALWAYS_SEARCH_USER_PATHS = NO;
181 | CLANG_ANALYZER_NONNULL = YES;
182 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
183 | CLANG_CXX_LIBRARY = "libc++";
184 | CLANG_ENABLE_MODULES = YES;
185 | CLANG_ENABLE_OBJC_ARC = YES;
186 | CLANG_WARN_BOOL_CONVERSION = YES;
187 | CLANG_WARN_CONSTANT_CONVERSION = YES;
188 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
189 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
190 | CLANG_WARN_EMPTY_BODY = YES;
191 | CLANG_WARN_ENUM_CONVERSION = YES;
192 | CLANG_WARN_INFINITE_RECURSION = YES;
193 | CLANG_WARN_INT_CONVERSION = YES;
194 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
195 | CLANG_WARN_SUSPICIOUS_MOVES = YES;
196 | CLANG_WARN_UNREACHABLE_CODE = YES;
197 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
198 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
199 | COPY_PHASE_STRIP = NO;
200 | DEBUG_INFORMATION_FORMAT = dwarf;
201 | ENABLE_STRICT_OBJC_MSGSEND = YES;
202 | ENABLE_TESTABILITY = YES;
203 | GCC_C_LANGUAGE_STANDARD = gnu99;
204 | GCC_DYNAMIC_NO_PIC = NO;
205 | GCC_NO_COMMON_BLOCKS = YES;
206 | GCC_OPTIMIZATION_LEVEL = 0;
207 | GCC_PREPROCESSOR_DEFINITIONS = (
208 | "DEBUG=1",
209 | "$(inherited)",
210 | );
211 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
212 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
213 | GCC_WARN_UNDECLARED_SELECTOR = YES;
214 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
215 | GCC_WARN_UNUSED_FUNCTION = YES;
216 | GCC_WARN_UNUSED_VARIABLE = YES;
217 | IPHONEOS_DEPLOYMENT_TARGET = 10.0;
218 | MTL_ENABLE_DEBUG_INFO = YES;
219 | ONLY_ACTIVE_ARCH = YES;
220 | SDKROOT = iphoneos;
221 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
222 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
223 | };
224 | name = Debug;
225 | };
226 | 4F6C9B4B1D5C641D000098B8 /* Release */ = {
227 | isa = XCBuildConfiguration;
228 | buildSettings = {
229 | ALWAYS_SEARCH_USER_PATHS = NO;
230 | CLANG_ANALYZER_NONNULL = YES;
231 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
232 | CLANG_CXX_LIBRARY = "libc++";
233 | CLANG_ENABLE_MODULES = YES;
234 | CLANG_ENABLE_OBJC_ARC = YES;
235 | CLANG_WARN_BOOL_CONVERSION = YES;
236 | CLANG_WARN_CONSTANT_CONVERSION = YES;
237 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
238 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
239 | CLANG_WARN_EMPTY_BODY = YES;
240 | CLANG_WARN_ENUM_CONVERSION = YES;
241 | CLANG_WARN_INFINITE_RECURSION = YES;
242 | CLANG_WARN_INT_CONVERSION = YES;
243 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
244 | CLANG_WARN_SUSPICIOUS_MOVES = YES;
245 | CLANG_WARN_UNREACHABLE_CODE = YES;
246 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
247 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
248 | COPY_PHASE_STRIP = NO;
249 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
250 | ENABLE_NS_ASSERTIONS = NO;
251 | ENABLE_STRICT_OBJC_MSGSEND = YES;
252 | GCC_C_LANGUAGE_STANDARD = gnu99;
253 | GCC_NO_COMMON_BLOCKS = YES;
254 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
255 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
256 | GCC_WARN_UNDECLARED_SELECTOR = YES;
257 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
258 | GCC_WARN_UNUSED_FUNCTION = YES;
259 | GCC_WARN_UNUSED_VARIABLE = YES;
260 | IPHONEOS_DEPLOYMENT_TARGET = 10.0;
261 | MTL_ENABLE_DEBUG_INFO = NO;
262 | SDKROOT = iphoneos;
263 | SWIFT_COMPILATION_MODE = wholemodule;
264 | SWIFT_OPTIMIZATION_LEVEL = "-O";
265 | VALIDATE_PRODUCT = YES;
266 | };
267 | name = Release;
268 | };
269 | 4F6C9B4D1D5C641D000098B8 /* Debug */ = {
270 | isa = XCBuildConfiguration;
271 | buildSettings = {
272 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
273 | DEVELOPMENT_TEAM = 35DWKWL79J;
274 | INFOPLIST_FILE = NotificationBadgeExample/Info.plist;
275 | LD_RUNPATH_SEARCH_PATHS = (
276 | "$(inherited)",
277 | "@executable_path/Frameworks",
278 | );
279 | PRODUCT_BUNDLE_IDENTIFIER = net.crofis.NotificationBadgeExample;
280 | PRODUCT_NAME = "$(TARGET_NAME)";
281 | SWIFT_VERSION = 5.0;
282 | };
283 | name = Debug;
284 | };
285 | 4F6C9B4E1D5C641D000098B8 /* Release */ = {
286 | isa = XCBuildConfiguration;
287 | buildSettings = {
288 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
289 | DEVELOPMENT_TEAM = 35DWKWL79J;
290 | INFOPLIST_FILE = NotificationBadgeExample/Info.plist;
291 | LD_RUNPATH_SEARCH_PATHS = (
292 | "$(inherited)",
293 | "@executable_path/Frameworks",
294 | );
295 | PRODUCT_BUNDLE_IDENTIFIER = net.crofis.NotificationBadgeExample;
296 | PRODUCT_NAME = "$(TARGET_NAME)";
297 | SWIFT_VERSION = 5.0;
298 | };
299 | name = Release;
300 | };
301 | /* End XCBuildConfiguration section */
302 |
303 | /* Begin XCConfigurationList section */
304 | 4F6C9B351D5C641D000098B8 /* Build configuration list for PBXProject "NotificationBadgeExample" */ = {
305 | isa = XCConfigurationList;
306 | buildConfigurations = (
307 | 4F6C9B4A1D5C641D000098B8 /* Debug */,
308 | 4F6C9B4B1D5C641D000098B8 /* Release */,
309 | );
310 | defaultConfigurationIsVisible = 0;
311 | defaultConfigurationName = Release;
312 | };
313 | 4F6C9B4C1D5C641D000098B8 /* Build configuration list for PBXNativeTarget "NotificationBadgeExample" */ = {
314 | isa = XCConfigurationList;
315 | buildConfigurations = (
316 | 4F6C9B4D1D5C641D000098B8 /* Debug */,
317 | 4F6C9B4E1D5C641D000098B8 /* Release */,
318 | );
319 | defaultConfigurationIsVisible = 0;
320 | defaultConfigurationName = Release;
321 | };
322 | /* End XCConfigurationList section */
323 |
324 | /* Begin XCRemoteSwiftPackageReference section */
325 | CF778DDF25383FDC00D71C25 /* XCRemoteSwiftPackageReference "." */ = {
326 | isa = XCRemoteSwiftPackageReference;
327 | repositoryURL = ../;
328 | requirement = {
329 | kind = upToNextMajorVersion;
330 | minimumVersion = 1.2.0;
331 | };
332 | };
333 | /* End XCRemoteSwiftPackageReference section */
334 |
335 | /* Begin XCSwiftPackageProductDependency section */
336 | CF778DE025383FDC00D71C25 /* EasyNotificationBadge */ = {
337 | isa = XCSwiftPackageProductDependency;
338 | package = CF778DDF25383FDC00D71C25 /* XCRemoteSwiftPackageReference "." */;
339 | productName = EasyNotificationBadge;
340 | };
341 | /* End XCSwiftPackageProductDependency section */
342 | };
343 | rootObject = 4F6C9B321D5C641D000098B8 /* Project object */;
344 | }
345 |
--------------------------------------------------------------------------------
/Example/NotificationBadgeExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Example/NotificationBadgeExample/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.swift
3 | // NotificationBadgeExample
4 | //
5 | // Created by Antonio Zaitoun on 8/11/16.
6 | // Copyright © Crofis. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | @UIApplicationMain
12 | class AppDelegate: UIResponder, UIApplicationDelegate {
13 |
14 | var window: UIWindow?
15 |
16 | @nonobjc
17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
18 | // Override point for customization after application launch.
19 | return true
20 | }
21 |
22 | func applicationWillResignActive(_ application: UIApplication) {
23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
25 | }
26 |
27 | func applicationDidEnterBackground(_ application: UIApplication) {
28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
30 | }
31 |
32 | func applicationWillEnterForeground(_ application: UIApplication) {
33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
34 | }
35 |
36 | func applicationDidBecomeActive(_ application: UIApplication) {
37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
38 | }
39 |
40 | func applicationWillTerminate(_ application: UIApplication) {
41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/Example/NotificationBadgeExample/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "20x20",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "20x20",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "29x29",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "29x29",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "40x40",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "40x40",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "iphone",
35 | "size" : "60x60",
36 | "scale" : "2x"
37 | },
38 | {
39 | "idiom" : "iphone",
40 | "size" : "60x60",
41 | "scale" : "3x"
42 | }
43 | ],
44 | "info" : {
45 | "version" : 1,
46 | "author" : "xcode"
47 | }
48 | }
--------------------------------------------------------------------------------
/Example/NotificationBadgeExample/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Example/NotificationBadgeExample/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/Example/NotificationBadgeExample/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 | LSRequiresIPhoneOS
22 |
23 | UILaunchStoryboardName
24 | LaunchScreen
25 | UIMainStoryboardFile
26 | Main
27 | UIRequiredDeviceCapabilities
28 |
29 | armv7
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 | UIInterfaceOrientationLandscapeLeft
35 | UIInterfaceOrientationLandscapeRight
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/Example/NotificationBadgeExample/ViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.swift
3 | // NotificationBadgeExample
4 | //
5 | // Created by Antonio Zaitoun on 8/11/16.
6 | // Copyright © Crofis. All rights reserved.
7 | //
8 |
9 | import UIKit
10 | import EasyNotificationBadge
11 |
12 | class ViewController: UIViewController {
13 | @IBOutlet weak var badgeButton: UIButton!
14 |
15 | var appearance = BadgeAppearance(animate: true)
16 |
17 | override func viewDidLoad() {
18 | super.viewDidLoad()
19 | let when = DispatchTime.now() + 1 // change 2 to desired number of seconds
20 | DispatchQueue.main.asyncAfter(deadline: when) { [self] in
21 | self.badgeButton.badge(text: "1", appearance: appearance)
22 | }
23 |
24 | badgeButton.addTarget(self, action: #selector(didSelectButton(sender:)), for: .touchUpInside)
25 | }
26 |
27 | @objc
28 | func didSelectButton(sender: UIButton) {
29 | defer {
30 | sender.tag += 1
31 | }
32 | if sender.tag == 0 {
33 | sender.badge(text: "Easy", appearance: appearance)
34 | } else if sender.tag == 1 {
35 | sender.badge(text: nil, appearance: appearance)
36 | } else {
37 | sender.badge(text: "\(sender.tag - 1)", appearance: appearance)
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 Antonio Zaitoun
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Package.swift:
--------------------------------------------------------------------------------
1 | // swift-tools-version:5.3
2 |
3 | import PackageDescription
4 |
5 | let package = Package(
6 | name: "EasyNotificationBadge",
7 | products: [
8 | .library(
9 | name: "EasyNotificationBadge",
10 | targets: ["EasyNotificationBadge"]),
11 | ],
12 | targets: [
13 | .target(
14 | name: "EasyNotificationBadge",
15 | dependencies: []),
16 | ]
17 | )
18 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | []()
5 | []()
6 | []()
7 |
8 | ## Installation
9 |
10 | ### CocoaPods
11 |
12 | ```bash
13 | pod 'EasyNotificationBadge'
14 | ```
15 |
16 | ### Swift Package Manager
17 |
18 | You can use [The Swift Package Manager](https://swift.org/package-manager) to install `EasyNotificationBadge` by adding the proper description to your `Package.swift` file:
19 |
20 | ```swift
21 | // swift-tools-version:4.0
22 | import PackageDescription
23 |
24 | let package = Package(
25 | name: "YOUR_PROJECT_NAME",
26 | dependencies: [
27 | .package(url: "https://github.com/Minitour/EasyNotificationBadge.git", from: "1.2.4"),
28 | ]
29 | )
30 | ```
31 | Then run `swift build` whenever you're ready.
32 |
33 | Or simply drag and drop ```NSBadge.swift``` to your project.
34 |
35 | ## Usage
36 |
37 | To add a badge with default settings use this (This also applies to updating an existing badge):
38 | ```swift
39 | view.badge(text: "5")
40 | ```
41 |
42 | To remove the badge:
43 |
44 | ```swift
45 | view.badge(text: nil)
46 | ```
47 |
48 | ## Advanced Usage
49 |
50 | ```swift
51 | var badgeAppearance = BadgeAppearance()
52 | badgeAppearance.backgroundColor = UIColor.blue //default is red
53 | badgeAppearance.textColor = UIColor.white // default is white
54 | badgeAppearance.textAlignment = .center //default is center
55 | badgeAppearance.textSize = 15 //default is 12
56 | badgeAppearance.distanceFromCenterX = 15 //default is nil
57 | badgeAppearance.distanceFromCenterY = -10 //default is nil
58 | badgeAppearance.allowShadow = true
59 | badgeAppearance.borderColor = .blue
60 | badgeAppearance.borderWidth = 1
61 | view.badge(text: "Your text", appearance: badgeAppearance)
62 | ```
63 |
64 | ### Important
65 | 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.
66 |
--------------------------------------------------------------------------------
/Screenshots/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Minitour/EasyNotificationBadge/2774998af193a396b1842c0727fe52c2bd217ae2/Screenshots/.DS_Store
--------------------------------------------------------------------------------
/Screenshots/heading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Minitour/EasyNotificationBadge/2774998af193a396b1842c0727fe52c2bd217ae2/Screenshots/heading.gif
--------------------------------------------------------------------------------
/Screenshots/ss1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Minitour/EasyNotificationBadge/2774998af193a396b1842c0727fe52c2bd217ae2/Screenshots/ss1.png
--------------------------------------------------------------------------------
/Screenshots/ss2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Minitour/EasyNotificationBadge/2774998af193a396b1842c0727fe52c2bd217ae2/Screenshots/ss2.png
--------------------------------------------------------------------------------
/Screenshots/ss3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Minitour/EasyNotificationBadge/2774998af193a396b1842c0727fe52c2bd217ae2/Screenshots/ss3.png
--------------------------------------------------------------------------------
/Screenshots/ss4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Minitour/EasyNotificationBadge/2774998af193a396b1842c0727fe52c2bd217ae2/Screenshots/ss4.png
--------------------------------------------------------------------------------
/Screenshots/ss5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Minitour/EasyNotificationBadge/2774998af193a396b1842c0727fe52c2bd217ae2/Screenshots/ss5.png
--------------------------------------------------------------------------------
/Screenshots/ss6.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Minitour/EasyNotificationBadge/2774998af193a396b1842c0727fe52c2bd217ae2/Screenshots/ss6.PNG
--------------------------------------------------------------------------------
/Sources/EasyNotificationBadge/EasyNotificationBadge.swift:
--------------------------------------------------------------------------------
1 | //
2 | // EasyNotificationBadge.swift
3 | //
4 | // Created by Antonio Zaitoun on 8/10/16.
5 | // Copyright © 2016 Crofis. All rights reserved.
6 | //
7 |
8 | import UIKit
9 |
10 | extension UIView {
11 | /// Assign badge with only text.
12 | ///
13 | /// - Parameter text: The badge value, use nil to remove exsiting badge.
14 | @objc public func badge(text badgeText: String?) {
15 | badge(text: badgeText, appearance: BadgeAppearance())
16 | }
17 |
18 |
19 | /// Assign badge with text,insets, and appearance.
20 | /// - Parameters:
21 | /// - text: The badge value, use nil to remove exsiting badge.
22 | /// - appearance: The appearance of the badge.
23 | public func badge(text badgeText: String?, appearance: BadgeAppearance) {
24 | // Create badge label
25 | var badgeLabel: BadgeLabel?
26 | var doesBadgeExist = false
27 |
28 | // Find badge in subviews if exists
29 | for view in self.subviews where view.tag == 1 && view is BadgeLabel {
30 | badgeLabel = view as? BadgeLabel
31 | }
32 |
33 | // If assigned text is nil (request to remove badge) and badge label is not nil:
34 | if badgeText == nil && badgeLabel != nil {
35 | removeBadgeLabel(badgeLabel!, appearance: appearance)
36 | return
37 | } else if badgeText == nil && badgeLabel == nil {
38 | return
39 | }
40 |
41 | // Badge label is nil (There was no previous badge)
42 | if badgeLabel == nil {
43 | // init badge label variable
44 | badgeLabel = BadgeLabel()
45 | // assign tag to badge label
46 | badgeLabel?.tag = 1
47 | } else {
48 | doesBadgeExist = true
49 | }
50 |
51 | guard let badgeLabelView = badgeLabel else { return }
52 |
53 | let oldWidth: CGFloat? = doesBadgeExist ? badgeLabelView.frame.width : nil
54 |
55 | // Set the text on the badge label
56 | badgeLabelView.text = badgeText
57 | // Set font size
58 | badgeLabelView.font = appearance.font
59 | badgeLabelView.sizeToFit()
60 |
61 | layoutLabel(badgeLabelView, appearance: appearance, doesBadgeExist: doesBadgeExist)
62 |
63 | applyStyle(label: badgeLabelView, appearance: appearance)
64 |
65 | // badge does not exist, meaning we are adding a new one
66 | animateBadgeAppearance(label: badgeLabelView, appearance: appearance, doesBadgeExist: doesBadgeExist, oldWidth: oldWidth)
67 | }
68 |
69 | fileprivate func layoutLabel(_ label: BadgeLabel, appearance: BadgeAppearance, doesBadgeExist: Bool) {
70 | // get current badge size
71 | // calculate width and height with minimum height and width of 20
72 | let badgeSize = label.frame.size
73 | var height = max(18, (badgeSize.height) + 5.0)
74 | var width = max(height, (badgeSize.width) + 10.0)
75 | if let radius = appearance.radius {
76 | height = radius
77 | width = radius
78 | }
79 | label.frame.size = CGSize(width: width, height: height)
80 |
81 | // add to subview
82 | if doesBadgeExist {
83 | // delete constraints
84 | NSLayoutConstraint.deactivate(label.constraints)
85 | } else {
86 | addSubview(label)
87 | // disable auto resizing mask
88 | label.translatesAutoresizingMaskIntoConstraints = false
89 | }
90 |
91 | // The distance from the center of the view (vertically)
92 | let centerY = appearance.distanceFromCenterY == nil ? -(bounds.size.height / 2) : appearance.distanceFromCenterY!
93 | // The distance from the center of the view (horizontally)
94 | let centerX = appearance.distanceFromCenterX == nil ? (bounds.size.width / 2) : appearance.distanceFromCenterX!
95 |
96 | // add constraints
97 | NSLayoutConstraint.activate([
98 | label.heightAnchor.constraint(equalToConstant: height),
99 | label.widthAnchor.constraint(equalToConstant: width),
100 | label.centerXAnchor.constraint(equalTo: centerXAnchor, constant: centerX),
101 | label.centerYAnchor.constraint(equalTo: centerYAnchor, constant: centerY)
102 | ])
103 | }
104 |
105 | fileprivate func applyStyle(label: BadgeLabel, appearance: BadgeAppearance) {
106 |
107 | // set the allignment
108 | label.textAlignment = appearance.textAlignment
109 | // set background color
110 | label.layer.backgroundColor = appearance.backgroundColor.cgColor
111 | // set text color
112 | label.textColor = appearance.textColor
113 |
114 | label.layer.borderColor = appearance.borderColor.cgColor
115 | label.layer.borderWidth = appearance.borderWidth
116 |
117 | let badgeLabelHeight = label.frame.size.height
118 | // corner radius
119 | label.layer.cornerRadius = badgeLabelHeight / 2
120 |
121 | // setup shadow
122 | if appearance.allowShadow {
123 | label.layer.shadowOffset = CGSize(width: 1, height: 1)
124 | label.layer.shadowRadius = 1
125 | label.layer.shadowOpacity = 0.5
126 | label.layer.shadowColor = UIColor.black.cgColor
127 | }
128 | }
129 |
130 | fileprivate func removeBadgeLabel(_ label: BadgeLabel, appearance: BadgeAppearance) {
131 | if appearance.animate {
132 | UIView.animate(withDuration: appearance.duration, animations: {
133 | label.alpha = 0.0
134 | label.transform = CGAffineTransform(scaleX: 0.1, y: 0.1)
135 | }, completion: { (_) in
136 | label.removeFromSuperview()
137 | })
138 | } else {
139 | label.removeFromSuperview()
140 | }
141 |
142 | }
143 |
144 | fileprivate func animateBadgeAppearance(label: BadgeLabel, appearance: BadgeAppearance, doesBadgeExist: Bool, oldWidth: CGFloat?) {
145 | if !doesBadgeExist {
146 | // should it animate?
147 | if appearance.animate {
148 | label.transform = CGAffineTransform(scaleX: 0, y: 0)
149 |
150 | UIView.animate(withDuration: appearance.duration,
151 | delay: 0,
152 | usingSpringWithDamping: 0.5,
153 | initialSpringVelocity: 0.5,
154 | options: [],
155 | animations: {
156 | label.transform = .identity
157 | },
158 | completion: nil)
159 | }
160 | } else {
161 | if appearance.animate, let oldWidth = oldWidth {
162 | let currentWidth = label.frame.width
163 | label.frame.size.width = oldWidth
164 | UIView.animate(withDuration: appearance.duration) {
165 | label.frame.size.width = currentWidth
166 | }
167 | }
168 | }
169 | }
170 | }
171 |
172 | extension UIBarButtonItem {
173 | /// Assign badge with only text.
174 | @objc public func badge(text: String?) {
175 | badge(text: text, appearance: BadgeAppearance())
176 | }
177 |
178 | public func badge(text badgeText: String?, appearance: BadgeAppearance = .default) {
179 | if let view = badgeViewHolder {
180 | getView(in: view).badge(text: badgeText, appearance: appearance)
181 | } else {
182 | NSLog("Attempted setting badge with value '\(badgeText ?? "nil")' on a nil UIBarButtonItem view.")
183 | }
184 | }
185 |
186 | private var badgeViewHolder: UIView? {
187 | return value(forKey: "view") as? UIView
188 | }
189 |
190 | private func getView(in holder: UIView) -> UIView {
191 | for sub in holder.subviews where "\(type(of: sub))" == "_UIModernBarButton" {
192 | return sub
193 | }
194 |
195 | return holder
196 | }
197 | }
198 |
199 | /// BadgeLabel - This class is made to avoid confusion with other subviews that might be of type UILabel.
200 | @objc class BadgeLabel: UILabel {
201 |
202 | override func removeFromSuperview() {
203 | super.removeFromSuperview()
204 | NSLayoutConstraint.deactivate(constraints)
205 | }
206 | }
207 |
208 | /// BadgeAppearance - This struct is used to design the badge.
209 | public struct BadgeAppearance {
210 |
211 | public static var `default`: BadgeAppearance {
212 | return .init()
213 | }
214 |
215 | public var font: UIFont = .systemFont(ofSize: 12)
216 | public var textAlignment: NSTextAlignment = .center
217 | public var borderColor: UIColor = .clear
218 | public var borderWidth: CGFloat = 0.0
219 | public var allowShadow: Bool = false
220 | public var backgroundColor: UIColor = .red
221 | public var textColor: UIColor = .white
222 | public var animate: Bool = true
223 | public var duration: TimeInterval = 0.2
224 | public var distanceFromCenterY: CGFloat?
225 | public var distanceFromCenterX: CGFloat?
226 | public var radius: CGFloat?
227 |
228 |
229 | public init(font: UIFont = .systemFont(ofSize: 12),
230 | textAlignment: NSTextAlignment = .center,
231 | borderColor: UIColor = .clear,
232 | borderWidth: CGFloat = 0.0,
233 | allowShadow: Bool = false,
234 | backgroundColor: UIColor = .red,
235 | textColor: UIColor = .white,
236 | animate: Bool = true,
237 | duration: TimeInterval = 0.2,
238 | distanceFromCenterY: CGFloat? = nil,
239 | distanceFromCenterX: CGFloat? = nil,
240 | radius: CGFloat? = nil) {
241 | self.font = font
242 | self.textAlignment = textAlignment
243 | self.borderColor = borderColor
244 | self.borderWidth = borderWidth
245 | self.allowShadow = allowShadow
246 | self.backgroundColor = backgroundColor
247 | self.textColor = textColor
248 | self.animate = animate
249 | self.duration = duration
250 | self.distanceFromCenterY = distanceFromCenterY
251 | self.distanceFromCenterX = distanceFromCenterX
252 | self.radius = radius
253 | }
254 | }
255 |
--------------------------------------------------------------------------------