Created
August 17, 2017 18:09
-
-
Save birkir/0a1b7f459c12ff5bc68dee1ea1108c99 to your computer and use it in GitHub Desktop.
Background color overlay for navbar blur
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Line 477 | |
if (![viewController.navigationController.navigationBar viewWithTag:BLUR_NAVBAR_TAG]) { | |
UIBlurEffectStyle *blurStyle = UIBlurEffectStyleLight; | |
NSString *navBarBlurStyle = self.navigatorStyle[@"navBarBlurStyle"]; | |
if (navBarBlurStyle) { | |
if ([navBarBlurStyle isEqualToString:@"extralight"]) { | |
blurStyle = UIBlurEffectStyleExtraLight; | |
} | |
if ([navBarBlurStyle isEqualToString:@"dark"]) { | |
blurStyle = UIBlurEffectStyleDark; | |
} | |
if ([navBarBlurStyle isEqualToString:@"regular"]) { | |
blurStyle = UIBlurEffectStyleRegular; | |
} | |
if ([navBarBlurStyle isEqualToString:@"prominent"]) { | |
blurStyle = UIBlurEffectStyleProminent; | |
} | |
} | |
[self storeOriginalNavBarImages]; | |
[viewController.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; | |
viewController.navigationController.navigationBar.shadowImage = [UIImage new]; | |
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:blurStyle]; | |
UIVisualEffectView *blur = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; | |
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame]; | |
blur.frame = CGRectMake(0, -1 * statusBarFrame.size.height, viewController.navigationController.navigationBar.frame.size.width, viewController.navigationController.navigationBar.frame.size.height + statusBarFrame.size.height); | |
blur.userInteractionEnabled = NO; | |
blur.tag = BLUR_NAVBAR_TAG; | |
// Background color overlay for blur | |
if (navBarBackgroundColor) { | |
UIColor *color = navBarBackgroundColor != (id)[NSNull null] ? [RCTConvert UIColor:navBarBackgroundColor] : nil; | |
UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectZero]; | |
backgroundView.frame = CGRectMake(0, -1 * statusBarFrame.size.height, viewController.navigationController.navigationBar.frame.size.width, viewController.navigationController.navigationBar.frame.size.height + statusBarFrame.size.height); | |
backgroundView.backgroundColor = color; | |
[viewController.navigationController.navigationBar insertSubview:backgroundView atIndex:0]; | |
[viewController.navigationController.navigationBar sendSubviewToBack:backgroundView]; | |
} | |
[viewController.navigationController.navigationBar insertSubview:blur atIndex:0]; | |
[viewController.navigationController.navigationBar sendSubviewToBack:blur]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment