From 78a516d3fd45d04c549c337c19740dab5219c9a9 Mon Sep 17 00:00:00 2001 From: zxwcool Date: Fri, 1 Jan 2016 11:04:58 +0800 Subject: [PATCH 1/6] Customize the badge size Change the value of the property named badgeMinWidth to customize the size of the badge. if u want to use the default size, only not to set the value of badgeMinWidth or set the value to zero. --- Pod/Classes/JSBadgeView.h | 0 Pod/Classes/JSBadgeView.m | 11 ++++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) mode change 100644 => 100755 Pod/Classes/JSBadgeView.h mode change 100644 => 100755 Pod/Classes/JSBadgeView.m diff --git a/Pod/Classes/JSBadgeView.h b/Pod/Classes/JSBadgeView.h old mode 100644 new mode 100755 diff --git a/Pod/Classes/JSBadgeView.m b/Pod/Classes/JSBadgeView.m old mode 100644 new mode 100755 index e3c5366..fba0d71 --- a/Pod/Classes/JSBadgeView.m +++ b/Pod/Classes/JSBadgeView.m @@ -42,9 +42,9 @@ of this software and associated documentation files (the "Software"), to deal #endif static const CGFloat JSBadgeViewShadowRadius = 1.0f; -static const CGFloat JSBadgeViewHeight = 16.0f; -static const CGFloat JSBadgeViewTextSideMargin = 8.0f; -static const CGFloat JSBadgeViewCornerRadius = 10.0f; +CGFloat JSBadgeViewHeight = 16.0f; +CGFloat JSBadgeViewTextSideMargin = 8.0f; +CGFloat JSBadgeViewCornerRadius = 10.0f; // Thanks to Peter Steinberger: https://gist.github.com/steipete/6526860 static BOOL JSBadgeViewIsUIKitFlatMode(void) @@ -148,6 +148,11 @@ - (void)layoutSubviews const CGFloat textWidth = [self sizeOfTextForCurrentSettings].width; const CGFloat marginToDrawInside = [self marginToDrawInside]; + if (_badgeMinWidth > 0) { + JSBadgeViewTextSideMargin = _badgeMinWidth; + JSBadgeViewHeight = 2*JSBadgeViewTextSideMargin; + JSBadgeViewCornerRadius = JSBadgeViewTextSideMargin + 2; + } const CGFloat viewWidth = MAX(_badgeMinWidth, textWidth + JSBadgeViewTextSideMargin + (marginToDrawInside * 2)); const CGFloat viewHeight = JSBadgeViewHeight + (marginToDrawInside * 2); From d091a27cb7ef6857da08acb679c9a8881738a36a Mon Sep 17 00:00:00 2001 From: zxwcool Date: Fri, 1 Jan 2016 11:41:46 +0800 Subject: [PATCH 2/6] install pod reinstall pod or not run --- Example/JSBadgeView.xcodeproj/project.pbxproj | 32 +++++++++++++++++++ Example/Podfile.lock | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Example/JSBadgeView.xcodeproj/project.pbxproj b/Example/JSBadgeView.xcodeproj/project.pbxproj index 5a640da..0a64d16 100644 --- a/Example/JSBadgeView.xcodeproj/project.pbxproj +++ b/Example/JSBadgeView.xcodeproj/project.pbxproj @@ -206,6 +206,7 @@ 6003F587195388D20070C39A /* Frameworks */, 6003F588195388D20070C39A /* Resources */, 2B276D4DEFA48597D1EAFEA4 /* Copy Pods Resources */, + 1A75C54995B6326D75562D23 /* Embed Pods Frameworks */, ); buildRules = ( ); @@ -225,6 +226,7 @@ 6003F5AB195388D20070C39A /* Frameworks */, 6003F5AC195388D20070C39A /* Resources */, 5AE0D8D1A81A1FC823A57EFA /* Copy Pods Resources */, + 5D77F70A8B319118B80C1472 /* Embed Pods Frameworks */, ); buildRules = ( ); @@ -308,6 +310,21 @@ shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; + 1A75C54995B6326D75562D23 /* Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Embed Pods Frameworks"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-JSBadgeView/Pods-JSBadgeView-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; 2B276D4DEFA48597D1EAFEA4 /* Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -338,6 +355,21 @@ shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Tests/Pods-Tests-resources.sh\"\n"; showEnvVarsInLog = 0; }; + 5D77F70A8B319118B80C1472 /* Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Embed Pods Frameworks"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Tests/Pods-Tests-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; 7C90B127821C2227416080E0 /* Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 1131a77..24cc446 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -17,4 +17,4 @@ SPEC CHECKSUMS: JSBadgeView: 3861ddee41094284d9468e6d0af5107f703aaac5 Specta: 96fe05fe5c7348b5223f85e862904f6e832abb14 -COCOAPODS: 0.37.1 +COCOAPODS: 0.39.0 From 7cf057083be352a7d577c7c638e5700d56b6732b Mon Sep 17 00:00:00 2001 From: zxwcool Date: Fri, 1 Jan 2016 11:54:19 +0800 Subject: [PATCH 3/6] customize the bage size if u want to customize the bage size, set the badgeMinWidth property to a nonzero value, if u want to use the default size, just not set any value to the badgeMinWidth property. --- Example/JSBadgeView/JSViewController.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Example/JSBadgeView/JSViewController.m b/Example/JSBadgeView/JSViewController.m index 24e2c76..50ce67f 100644 --- a/Example/JSBadgeView/JSViewController.m +++ b/Example/JSBadgeView/JSViewController.m @@ -75,6 +75,8 @@ - (void)loadView rectangle.layer.shadowPath = rectangleShadowPath; JSBadgeView *badgeView = [[JSBadgeView alloc] initWithParentView:rectangle alignment:JSBadgeViewAlignmentTopRight]; + //if u want to customize the bage size, set the badgeMinWidth property to a nonzero value, if u want to use the default size, just not set any value to the badgeMinWidth property. +// badgeView.badgeMinWidth = 5; // customize the bage size, u should also set proper font size. badgeView.badgeText = [NSString stringWithFormat:@"%d", i]; [scrollView addSubview:rectangle]; From 2e2d00f6034e1175614bef1f081fd3126cab2669 Mon Sep 17 00:00:00 2001 From: zxwcool Date: Fri, 1 Jan 2016 12:27:26 +0800 Subject: [PATCH 4/6] Revert "Customize the badge size" This reverts commit 78a516d3fd45d04c549c337c19740dab5219c9a9. --- Pod/Classes/JSBadgeView.h | 0 Pod/Classes/JSBadgeView.m | 11 +++-------- 2 files changed, 3 insertions(+), 8 deletions(-) mode change 100755 => 100644 Pod/Classes/JSBadgeView.h mode change 100755 => 100644 Pod/Classes/JSBadgeView.m diff --git a/Pod/Classes/JSBadgeView.h b/Pod/Classes/JSBadgeView.h old mode 100755 new mode 100644 diff --git a/Pod/Classes/JSBadgeView.m b/Pod/Classes/JSBadgeView.m old mode 100755 new mode 100644 index fba0d71..e3c5366 --- a/Pod/Classes/JSBadgeView.m +++ b/Pod/Classes/JSBadgeView.m @@ -42,9 +42,9 @@ of this software and associated documentation files (the "Software"), to deal #endif static const CGFloat JSBadgeViewShadowRadius = 1.0f; -CGFloat JSBadgeViewHeight = 16.0f; -CGFloat JSBadgeViewTextSideMargin = 8.0f; -CGFloat JSBadgeViewCornerRadius = 10.0f; +static const CGFloat JSBadgeViewHeight = 16.0f; +static const CGFloat JSBadgeViewTextSideMargin = 8.0f; +static const CGFloat JSBadgeViewCornerRadius = 10.0f; // Thanks to Peter Steinberger: https://gist.github.com/steipete/6526860 static BOOL JSBadgeViewIsUIKitFlatMode(void) @@ -148,11 +148,6 @@ - (void)layoutSubviews const CGFloat textWidth = [self sizeOfTextForCurrentSettings].width; const CGFloat marginToDrawInside = [self marginToDrawInside]; - if (_badgeMinWidth > 0) { - JSBadgeViewTextSideMargin = _badgeMinWidth; - JSBadgeViewHeight = 2*JSBadgeViewTextSideMargin; - JSBadgeViewCornerRadius = JSBadgeViewTextSideMargin + 2; - } const CGFloat viewWidth = MAX(_badgeMinWidth, textWidth + JSBadgeViewTextSideMargin + (marginToDrawInside * 2)); const CGFloat viewHeight = JSBadgeViewHeight + (marginToDrawInside * 2); From 4ced88c474c63cb8fe16802211dc9a16a2f299e0 Mon Sep 17 00:00:00 2001 From: zxwcool Date: Fri, 1 Jan 2016 12:29:01 +0800 Subject: [PATCH 5/6] Revert "customize the bage size" This reverts commit 7cf057083be352a7d577c7c638e5700d56b6732b. --- Example/JSBadgeView/JSViewController.m | 2 -- 1 file changed, 2 deletions(-) diff --git a/Example/JSBadgeView/JSViewController.m b/Example/JSBadgeView/JSViewController.m index 50ce67f..24e2c76 100644 --- a/Example/JSBadgeView/JSViewController.m +++ b/Example/JSBadgeView/JSViewController.m @@ -75,8 +75,6 @@ - (void)loadView rectangle.layer.shadowPath = rectangleShadowPath; JSBadgeView *badgeView = [[JSBadgeView alloc] initWithParentView:rectangle alignment:JSBadgeViewAlignmentTopRight]; - //if u want to customize the bage size, set the badgeMinWidth property to a nonzero value, if u want to use the default size, just not set any value to the badgeMinWidth property. -// badgeView.badgeMinWidth = 5; // customize the bage size, u should also set proper font size. badgeView.badgeText = [NSString stringWithFormat:@"%d", i]; [scrollView addSubview:rectangle]; From 05574ba135aec2c68e5f335fbaefd23d68edd71d Mon Sep 17 00:00:00 2001 From: zxwcool Date: Sun, 3 Jan 2016 11:43:06 +0800 Subject: [PATCH 6/6] customize the bage size if u want to customize the bage size, set the badgeMinWidth property to a nonzero value, if u want to use the default size, just not set any value to the badgeMinWidth property. --- Example/JSBadgeView/JSViewController.m | 18 ++++++++++-------- Pod/Classes/JSBadgeView.m | 11 ++++++++--- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Example/JSBadgeView/JSViewController.m b/Example/JSBadgeView/JSViewController.m index 24e2c76..72957ae 100644 --- a/Example/JSBadgeView/JSViewController.m +++ b/Example/JSBadgeView/JSViewController.m @@ -64,17 +64,19 @@ - (void)loadView { UIView *rectangle = [[UIView alloc] initWithFrame:CGRectIntegral(CGRectMake(xOffset, yOffset, - rectangleBounds.size.width, - rectangleBounds.size.height))]; + rectangleBounds.size.width/3, + rectangleBounds.size.height/3))]; rectangle.backgroundColor = kSquareColor; - rectangle.layer.cornerRadius = kSquareCornerRadius; - rectangle.layer.shadowColor = [UIColor blackColor].CGColor; - rectangle.layer.shadowOffset = CGSizeMake(0.0f, 3.0f); - rectangle.layer.shadowOpacity = 0.4; - rectangle.layer.shadowRadius = 1.0; - rectangle.layer.shadowPath = rectangleShadowPath; +// rectangle.layer.cornerRadius = kSquareCornerRadius; +// rectangle.layer.shadowColor = [UIColor blackColor].CGColor; +// rectangle.layer.shadowOffset = CGSizeMake(0.0f, 3.0f); +// rectangle.layer.shadowOpacity = 0.4; +// rectangle.layer.shadowRadius = 1.0; +// rectangle.layer.shadowPath = rectangleShadowPath; JSBadgeView *badgeView = [[JSBadgeView alloc] initWithParentView:rectangle alignment:JSBadgeViewAlignmentTopRight]; + badgeView.badgeMinWidth = 5; + badgeView.badgeTextFont = [UIFont systemFontOfSize:8]; badgeView.badgeText = [NSString stringWithFormat:@"%d", i]; [scrollView addSubview:rectangle]; diff --git a/Pod/Classes/JSBadgeView.m b/Pod/Classes/JSBadgeView.m index e3c5366..fba0d71 100644 --- a/Pod/Classes/JSBadgeView.m +++ b/Pod/Classes/JSBadgeView.m @@ -42,9 +42,9 @@ of this software and associated documentation files (the "Software"), to deal #endif static const CGFloat JSBadgeViewShadowRadius = 1.0f; -static const CGFloat JSBadgeViewHeight = 16.0f; -static const CGFloat JSBadgeViewTextSideMargin = 8.0f; -static const CGFloat JSBadgeViewCornerRadius = 10.0f; +CGFloat JSBadgeViewHeight = 16.0f; +CGFloat JSBadgeViewTextSideMargin = 8.0f; +CGFloat JSBadgeViewCornerRadius = 10.0f; // Thanks to Peter Steinberger: https://gist.github.com/steipete/6526860 static BOOL JSBadgeViewIsUIKitFlatMode(void) @@ -148,6 +148,11 @@ - (void)layoutSubviews const CGFloat textWidth = [self sizeOfTextForCurrentSettings].width; const CGFloat marginToDrawInside = [self marginToDrawInside]; + if (_badgeMinWidth > 0) { + JSBadgeViewTextSideMargin = _badgeMinWidth; + JSBadgeViewHeight = 2*JSBadgeViewTextSideMargin; + JSBadgeViewCornerRadius = JSBadgeViewTextSideMargin + 2; + } const CGFloat viewWidth = MAX(_badgeMinWidth, textWidth + JSBadgeViewTextSideMargin + (marginToDrawInside * 2)); const CGFloat viewHeight = JSBadgeViewHeight + (marginToDrawInside * 2);