UIBarButtonItem-Badge icon indicating copy to clipboard operation
UIBarButtonItem-Badge copied to clipboard

Badge disappears when changing tintColor of item

Open Volchik17 opened this issue 8 years ago • 0 comments

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; }

Volchik17 avatar Jun 28 '16 08:06 Volchik17