Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

customize the bage size #56

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Example/JSBadgeView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
6003F587195388D20070C39A /* Frameworks */,
6003F588195388D20070C39A /* Resources */,
2B276D4DEFA48597D1EAFEA4 /* Copy Pods Resources */,
1A75C54995B6326D75562D23 /* Embed Pods Frameworks */,
);
buildRules = (
);
Expand All @@ -225,6 +226,7 @@
6003F5AB195388D20070C39A /* Frameworks */,
6003F5AC195388D20070C39A /* Resources */,
5AE0D8D1A81A1FC823A57EFA /* Copy Pods Resources */,
5D77F70A8B319118B80C1472 /* Embed Pods Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 10 additions & 8 deletions Example/JSBadgeView/JSViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ SPEC CHECKSUMS:
JSBadgeView: 3861ddee41094284d9468e6d0af5107f703aaac5
Specta: 96fe05fe5c7348b5223f85e862904f6e832abb14

COCOAPODS: 0.37.1
COCOAPODS: 0.39.0
11 changes: 8 additions & 3 deletions Pod/Classes/JSBadgeView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);

Expand Down