I am attempting to add a blur effect to a navigation bar and a status bar. My problem is that the blur goes great onto the navigation bar, but the status bar does not get blurred.
My question is: how can I extend the bounds to encompass the status bar?
I'm using the following method to create the blur effect:
- (void) addBlurEffect {
CGRect bounds = self.navigationController.navigationBar.bounds;
UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
visualEffectView.frame = bounds;
visualEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.navigationController.navigationBar addSubview:visualEffectView];
self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
[self.navigationController.navigationBar sendSubviewToBack:visualEffectView];
}
In my plist, I have View controller-based status bar appearance YES
In viewDidLoad I call a method:
- (void)configureView {
// style controls
self.addAirportButton.tintColor = [UIColor whiteColor];
// style background image
UIImageView *sidebarBackground = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sidebarBackground"]];
self.tableView.backgroundView = sidebarBackground;
// style navigation bar
self.navigationController.navigationBar.barStyle = UIStatusBarStyleLightContent;
// this makes navigation bar transparent
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
// style toolbar
self.navigationController.toolbar.translucent = YES;
self.dismissAdsButton.tintColor = [UIColor whiteColor];
Nothing else important gets done in viewDidLoad. When I build this, here is what the view looks like -- it's a tableViewController embedded in a NavigationController, and I'm using the excellent SWRevealViewController as well.
See how the status bar is not blurred:
Any help would be really appreciated!
UPDATE:
See answer below. Here is a screenshot of the implemented solution:
On iPhone 8 or earlier, the color goes all the way across the status bar. Here's what each color means: Your iPhone is using Screen Mirroring , or an app is actively using your location. Your iPhone is either recording sound or your screen.
In iOS 7, you can control the style of the status bar from an individual view controller and change it while the app runs. If you prefer to opt out of this behavior and set the status bar style by using the UIApplication statusBarStyle method, add the UIViewControllerBasedStatusBarAppearance key to an app’s Info.plist file and give it the value NO
A navigation bar appears at the top of an app screen, enabling navigation through a hierarchy of content. A navigation bar also provides a natural place to display a screen’s title — helping people orient themselves in your app or game — and it can include controls that affect the screen’s content.
Step 1 − Open Xcode → New Project → Single View Application → Let’s name it “TransparentViews” Step 2 − Embed the View Controller in Navigation Controller. Add Image View and shown and add image. Step 3 − Run the application without adding any piece of code for making status and navigation bar transparent.
I have been trying to accomplish similar effect, after tweaking with the UINavigationBar's API and could not achieve desired result, I found a workaround:
create a UIView the same size as your NavigationBar + StatusBar. That is, it would have a frame of (0, 0, w, 64), where w is the width of your screen. (I did this through Storyboard and used autolayout to set the width constraint to be equal to that of its superview)
set UIView's backgroundColor
to clear color.
make the navigationBar completely transparent with the following code:
navBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
navBar.shadowImage = UIImage()
navBar.translucent = true
now apply the blur effect to that View, this creates the illusion that the blur effect was from both the Navigation Bar and the Status Bar.
See this picture for achieved effect (sorry I can't post image yet due to reputation restriction).
Hope this helps.
UPDATE 2015-05-28:
This is how I achieved the aforementioned method in StoryBoard:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With