GiGaMaskTime/GIGA/Category/UINavigationBar+Custom.m

65 lines
1.7 KiB
Objective-C

//
// UINavigationBar+Custom.m
// GIGA
//
// Created by lianxiang on 2018/8/13.
// Copyright © 2018年 com.giga.ios. All rights reserved.
//
#import <objc/runtime.h>
#import "UINavigationBar+Custom.h"
static char overlayKey;
@implementation UINavigationBar (Custom)
- (UIView *)overlay
{
return objc_getAssociatedObject(self, &overlayKey);
}
- (void)setOverlay:(UIView *)overlay
{
objc_setAssociatedObject(self, &overlayKey, overlay, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (void)cnSetBackgroundColor:(UIColor *)backgroundColor
{
if (!self.overlay) {
[self setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.overlay = [[UIView alloc] initWithFrame:CGRectMake(0, -PhoneX_STATUBAR_H, [UIScreen mainScreen].bounds.size.width, CGRectGetHeight(self.bounds) + PhoneX_STATUBAR_H)];
self.overlay.userInteractionEnabled = NO;
self.overlay.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
[self insertSubview:self.overlay atIndex:0];
}
self.overlay.backgroundColor = [backgroundColor colorWithAlphaComponent:0.2];
}
- (void)cnReset
{
[self setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
[self.overlay removeFromSuperview];
self.overlay = nil;
}
-(void)setClearNav
{
[self setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
//设置那条横线直接隐藏
self.shadowImage = [[UIImage alloc] init];
if (self.overlay) {
[self.overlay removeFromSuperview];
self.overlay = nil;
}
}
-(void)setBackgroundImage{
[self setBackgroundImage:[UIImage imageNamed:@"nav_red_moment"] forBarMetrics:UIBarMetricsDefault];
}
@end