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 disappears when changing tintColor of item #24

Open
Volchik17 opened this issue Jun 28, 2016 · 0 comments
Open

Badge disappears when changing tintColor of item #24

Volchik17 opened this issue Jun 28, 2016 · 0 comments

Comments

@Volchik17
Copy link

Badge disappears when changing tintColor of item
Thats because internal view to which badge labels belongs recreated when tintColor changed.

i made workaround by checking superview of badge label:

-(UILabel_) badge {
UILabel_ lbl = objc_getAssociatedObject(self, &UIBarButtonItem_badgeKey);
if(lbl==nil || lbl.superview==nil || lbl.superview.superview==nil) {
lbl = [[UILabel alloc] initWithFrame:CGRectMake(self.badgeOriginX, self.badgeOriginY, 20, 20)];
[self setBadge:lbl];
[self badgeInit:lbl];
[self.customView addSubview:lbl];
lbl.textAlignment = NSTextAlignmentCenter;
}
return lbl;
}

also have to change badgeInit a little:

  • (void)badgeInit:(UIView*) badge
    {
    UIView *superview = nil;
    CGFloat defaultOriginX = 0;
    if (self.customView) {
    superview = self.customView;
    defaultOriginX = superview.frame.size.width - self.badge.frame.size.width/2;
    // Avoids badge to be clipped when animating its scale
    superview.clipsToBounds = NO;
    } else if ([self respondsToSelector:@selector(view)] && [(id)self view]) {
    superview = [(id)self view];
    defaultOriginX = superview.frame.size.width - badge.frame.size.width;
    }
    [superview addSubview:badge];

    // Default design initialization
    self.badgeBGColor = [UIColor redColor];
    self.badgeTextColor = [UIColor whiteColor];
    self.badgeFont = [UIFont systemFontOfSize:12.0];
    self.badgePadding = 6;
    self.badgeMinSize = 8;
    self.badgeOriginX = defaultOriginX;
    self.badgeOriginY = -4;
    self.shouldHideBadgeAtZero = YES;
    self.shouldAnimateBadge = YES;
    }

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