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

Update the badge position more frequently #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 7 additions & 17 deletions UIView+MGBadgeView.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ - (instancetype)initWithFrame:(CGRect)frame {
}

- (void)drawRect:(CGRect)rect {
[self mg_updateBadgeViewSize];
[self mg_updateBadgeViewPosition];
Copy link
Owner

@matteogobbi matteogobbi Feb 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the 2 lines above are necessary and I would prefer to not have these calls here.


if(_badgeValue != 0 || _displayIfZero) {

Expand Down Expand Up @@ -83,9 +85,7 @@ - (void)setBadgeValue:(NSInteger)badgeValue {

if(badgeValue != 0 || _displayIfZero) {
[self mg_updateBadgeViewSize];

if(_position == MGBadgePositionBest)
[self mg_updateBadgeViewPosition];
[self mg_updateBadgeViewPosition];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed if the position isn't best.
You probably want put back the old code and add a call to mg_updateBadgeViewSize (for all the changes from here to the end)


} else {
self.frame = CGRectZero;
Expand All @@ -107,9 +107,7 @@ - (void)setMinDiameter:(float)minDiameter {
if (_minDiameter != minDiameter) {
_minDiameter = minDiameter;

if(_position == MGBadgePositionBest)
[self mg_updateBadgeViewPosition];

[self mg_updateBadgeViewPosition];
[self setNeedsDisplay];
}
}
Expand Down Expand Up @@ -139,9 +137,7 @@ - (void)setOutlineWidth:(float)outlineWidth {
if(_outlineWidth != outlineWidth) {
_outlineWidth = outlineWidth;

if(_position == MGBadgePositionBest)
[self mg_updateBadgeViewPosition];

[self mg_updateBadgeViewPosition];
[self setNeedsDisplay];
}
}
Expand All @@ -151,11 +147,7 @@ - (void)setFont:(UIFont *)font {
_font = font;

[self mg_updateBadgeViewSize];

if(_position == MGBadgePositionBest)
[self mg_updateBadgeViewPosition];


[self mg_updateBadgeViewPosition];
[self setNeedsDisplay];
}
}
Expand All @@ -167,9 +159,7 @@ - (void)setDisplayIfZero:(BOOL)displayIfZero {
if(_badgeValue == 0) {
if(_displayIfZero) {
[self mg_updateBadgeViewSize];

if(_position == MGBadgePositionBest)
[self mg_updateBadgeViewPosition];
[self mg_updateBadgeViewPosition];
} else {
self.frame = CGRectZero;
}
Expand Down