设置导航栏透明

#import 

@interface UINavigationController (Extension)
/**
 *  设置导航栏透明
 */
@property (nonatomic, assign, getter = isNavigationBarLucency) BOOL navigationBarLucency;
@end
#import "UINavigationController+Extension.h"
#import 

static char *LucencyKey = "LucencyKey";

@implementation UINavigationController (Extension)

- (BOOL)isNavigationBarLucency {
    return objc_getAssociatedObject(self, LucencyKey);
}

- (void)setNavigationBarLucency:(BOOL)navigationBarLucency {
    objc_setAssociatedObject(self, LucencyKey, @(OBJC_ASSOCIATION_ASSIGN), OBJC_ASSOCIATION_ASSIGN);
    if (navigationBarLucency) {
        [self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
        [self.navigationBar setShadowImage:[UIImage new]];
    }else {
        [self.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
        [self.navigationBar setShadowImage:nil];
    }
}

@end

你可能感兴趣的:(设置导航栏透明)