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

Setting badgeText multiple times may cause the badge's size grow unexpectedly #5

Closed
PrideChung opened this issue Jul 1, 2014 · 1 comment

Comments

@PrideChung
Copy link

Here's what I encountered, I have a badge view inside a UITableViewCell with these layout settings

M13BadgeView *badgeView = [[M13BadgeView alloc] initWithFrame:CGRectMake(0, 0, 40, 21.0f)];
badgeView.verticalAlignment = M13BadgeViewVerticalAlignmentMiddle;
badgeView.horizontalAlignment = M13BadgeViewHorizontalAlignmentRight;
badgeView.alignmentShift = CGSizeMake(-15, 0);
badgeView.minimumWidth = 21;

Then every time when I set the badgeView's text, the badgeView's height grow by 1 point.

Turns out this is what happen in the implementation of - (void)autoSetBadgeFrame: After some calculation, the badgeView decided it's frame should be origin=(x=261.5, y=14.25) size=(width=21, height=21)

Then in the line 191 of M13BadgeView.m, you called:

frame = CGRectIntegral(frame);

After that CGRectIntegral call, the frame became origin=(x=261, y=14) size=(width=22, height=22)

The documentation states CGRectIntegral's returned value :

A rectangle with the smallest integer values for its origin and size that contains the source rectangle

Here's problem, it's not simply round up the number's, it may also increase the new frame's size to contain the old frame even if the size is already a rounded number. When the text is been set multiple times, you will see the size of the badge view keep growing.

Now it's up to you to decide how to deal with it.

Marxon13 added a commit that referenced this issue Jul 17, 2014
The badge should no longer grow unexpectedly.
@PrideChung
Copy link
Author

It's fixed, thanks for the hard work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant