ltebean / LTNavigationBar

UINavigationBar Category which allows you to change its appearance dynamically
MIT License
4.46k stars 677 forks source link

_setElementsAlpha didn't change backItem arrow alpha #32

Open ghost opened 8 years ago

ghost commented 8 years ago

If the navigation bar have a back button item it didn't change alpha value and is always displayed in statusbar

ghost commented 8 years ago

An easy way to solve it and simplify the method:

From: `- (void)lt_setElementsAlpha:(CGFloat)alpha { [[self valueForKey:@"_leftViews"] enumerateObjectsUsingBlock:^(UIView view, NSUInteger i, BOOL stop) { view.alpha = alpha; }];

[[self valueForKey:@"_rightViews"] enumerateObjectsUsingBlock:^(UIView *view, NSUInteger i, BOOL *stop) {
    view.alpha = alpha;
}];

UIView *titleView = [self valueForKey:@"_titleView"];
titleView.alpha = alpha;

// when viewController first load, the titleView maybe nil [[self subviews] enumerateObjectsUsingBlock:^(UIView obj, NSUInteger idx, BOOL stop) { if ([obj isKindOfClass:NSClassFromString(@"UINavigationItemView")]) { obj.alpha = alpha; *stop = YES; } }]; }`

To: `- (void)lt_setElementsAlpha:(CGFloat)alpha { self.tintColor = [self.tintColor colorWithAlphaComponent:alpha];

UIView *titleView = [self valueForKey:@"_titleView"];
titleView.alpha = alpha;

// when viewController first load, the titleView maybe nil [[self subviews] enumerateObjectsUsingBlock:^(UIView obj, NSUInteger idx, BOOL stop) { if ([obj isKindOfClass:NSClassFromString(@"UINavigationItemView")]) { obj.alpha = alpha; *stop = YES; } }]; }`