https://github.com/ltebean/LTNavigationBar/tree/swift3.0
动态更改 UINavigationBar 的外观很困难,所以我制作了这个库以使工作变得简单。
首先,导入此库
#import "UINavigationBar+Awesome.h"
该分类包括许多方法,可以帮助动态更改 UINavigationBar 的外观
@interface UINavigationBar (Awesome)
- (void)lt_setBackgroundColor:(UIColor *)backgroundColor;
- (void)lt_setElementsAlpha:(CGFloat)alpha;
- (void)lt_setTranslationY:(CGFloat)translationY;
- (void)lt_reset;
@end
您可以在任何想要的地方调用各种设置器,例如
[self.navigationController.navigationBar lt_setBackgroundColor:[UIColor blueColor]];
通常在 viewWillDisappear
中调用此方法以避免任何副作用
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.navigationController.navigationBar lt_reset];
}
详见示例~