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

Badge text support #8

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

swoolcock
Copy link

Adds support for text to badges (not just NSInteger).
Changes ellipse to a "pill" to support wider text.

ksti added a commit to ksti/UIView-MGBadgeView that referenced this pull request Feb 22, 2017
@ricsantos
Copy link

Hi @matteogobbi was wondering if you would eventually accept this PR? I am looking at adding image support to the badges as well, and will most likely continue from this branch to keep text support as well.

@ricsantos
Copy link

OK so I have added image support onto the same branch, so for better or worse it's also on this PR. If you would like one of the two features only (text or images) let us know and we will split the functionality and make a new PR.

NSString *stringToDraw = nil;
if(_badgeImage) {
stringToDraw = nil;
} else if(_badgeText) {
Copy link
Owner

Choose a reason for hiding this comment

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

can you transform:

if(_badgeImage) {
         stringToDraw = nil;
} else if(_badgeText) {

in

if(!_badgeImage) {
     if(_badgeText) {
         .....

?

Choose a reason for hiding this comment

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

Will do 👍

@@ -95,6 +117,43 @@ - (void)setBadgeValue:(NSInteger)badgeValue {
}
}

- (void)setBadgeText:(NSString *)badgeText {
if(![(badgeText ?: @"") isEqualToString:(_badgeText ?: @"")]) {
Copy link
Owner

Choose a reason for hiding this comment

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

would be nicer if you can bring this in a separated method, maybe a static function like MGEqualObjects(obj1, obj2) which checks nullability. Or otherwise use the normal isEqualToString and before that, just check if they are both nil, and in that case return.

Choose a reason for hiding this comment

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

Ok, I've simplified it to simply

    if(_badgeText != badgeText) {
        _badgeText = badgeText;

And tested, it has the same result.

Copy link
Owner

Choose a reason for hiding this comment

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

No dude sorry, even if they are NSString, I don't like to compare objects in this way. I gave you a suggest on how to approach, I don't like shortcut :)

static BOOL MGEqualObjects(NSString *string1, NSString *string2) {
    return (!string1 && !string2) || [string1 isEqualToString:string2];
}

@@ -95,6 +117,43 @@ - (void)setBadgeValue:(NSInteger)badgeValue {
}
}

- (void)setBadgeText:(NSString *)badgeText {
if(![(badgeText ?: @"") isEqualToString:(_badgeText ?: @"")]) {
_badgeText = [NSString stringWithString:(badgeText ?: @"")];
Copy link
Owner

Choose a reason for hiding this comment

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

so we can maybe also improve this line making assumptions before.

@ricsantos
Copy link

Hi @matteogobbi I have made the requested changes, ok to merge now?

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

Successfully merging this pull request may close these issues.

3 participants