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

badgeMargin property To Largen Badge #54

Open
wants to merge 2 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
8 changes: 8 additions & 0 deletions WZLBadge/Protocol/WZLBadgeProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ static char badgeFrameKey;
static char badgeCenterOffsetKey;
static char badgeMaximumBadgeNumberKey;
static char badgeRadiusKey;
static char badgeMarginKey;


typedef NS_ENUM(NSUInteger, WBadgeStyle)
{
Expand Down Expand Up @@ -66,6 +68,7 @@ typedef NS_ENUM(NSUInteger, WBadgeAnimType)
/* For x, negative number means left offset
For y, negative number means bottom offset */


@property (nonatomic, assign) WBadgeAnimType aniType; /* NOTE that this is not animation type of badge's
appearing, nor hidding*/

Expand All @@ -76,6 +79,11 @@ typedef NS_ENUM(NSUInteger, WBadgeAnimType)
@property (nonatomic, assign) CGFloat badgeRadius;
// nomal use for red dot style of badge


@property (nonatomic, assign) CGFloat badgeMargin;
/* 4 by default if not set use for WBadgeStyleNumber style of badge*/


/**
* show badge with red dot style and WBadgeAnimTypeNone by default.
*/
Expand Down
17 changes: 15 additions & 2 deletions WZLBadge/View/UIView+WZLBadge.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "CAAnimation+WAnimation.h"

#define kWZLBadgeDefaultFont ([UIFont boldSystemFontOfSize:9])
#define kWZLBadgeDefaultMargin (8.0)

#define kWZLBadgeDefaultMaximumBadgeNumber 99

Expand Down Expand Up @@ -137,8 +138,8 @@ - (void)showNumberBadgeWithValue:(NSInteger)value
[NSString stringWithFormat:@"%@", @(value)]);
[self adjustLabelWidth:self.badge];
CGRect frame = self.badge.frame;
frame.size.width += 4;
frame.size.height += 4;
frame.size.width += self.badgeMargin;
frame.size.height += self.badgeMargin;
if(CGRectGetWidth(frame) < CGRectGetHeight(frame)) {
frame.size.width = CGRectGetHeight(frame);
}
Expand Down Expand Up @@ -385,6 +386,18 @@ - (CGFloat)badgeRadius {
return [objc_getAssociatedObject(self, &badgeRadiusKey) floatValue];
}

- (void)setBadgeMargin:(CGFloat)badgeMargin {
objc_setAssociatedObject(self, &badgeMarginKey, [NSNumber numberWithFloat:badgeMargin], OBJC_ASSOCIATION_RETAIN);
if (!self.badge) {
[self badgeInit];
}
}

- (CGFloat)badgeMargin {
id margin = objc_getAssociatedObject(self, &badgeMarginKey);
return margin == nil ? kWZLBadgeDefaultMargin : [margin floatValue];
}

- (NSInteger)badgeMaximumBadgeNumber {
id obj = objc_getAssociatedObject(self, &badgeMaximumBadgeNumberKey);
if(obj != nil && [obj isKindOfClass:[NSNumber class]])
Expand Down