5
votes

I'm working on a map based iOS 11 application and want to make the status bar blurred exactly like it appears in the Apple maps.

This is how it looks on the Maps app: enter image description here

Currently, I'm using UIVisualEffectView to replicate this effect. Here's my code:

let blurEffect = UIBlurEffect(style: .regular)
blurredStatusBar = UIVisualEffectView(effect: blurEffect)
blurredStatusBar?.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(blurredStatusBar!)

However, whatever UIBlurEffect I use, I'm not able to replicate the effect like Maps app. Here's how it looks for different effects:

.regular enter image description here

.prominent enter image description here

.light enter image description here

.extraLight enter image description here

I just want to the blur the status bar, without adding any saturation, vibrancy or any white color tint.

There is an instance property - backgroundFilters, which, possibly could have helped me but unfortunately it is not available for layers on iOS.

One possible solution suggested here was to capture the UIView content inside an image, then blurring and showing it. However, this is not a feasible solution in my case because I've got a map underneath the status bar which can be panned. It does not makes sense to continuously capture the underneath map as an image and blur it while the map is being panned.

I tried using ILTranslucentView, which is a little subclass of UIView that provide native iOS 7+ blur (translucent) effect. This is how it appeared:

enter image description here

I tried a couple of different approaches like this, but to no use.

3
Hi, i think Apple did not use UIBlurEffect, in order to achieve this effect try to add this lib like a status bar viewRrrangeTop

3 Answers

2
votes

I found the solution for the above problem. I used VisualEffectView to achieve the effect. It lets you to customise the properties like colortint, blurRadius, scale of blur of your VisualEffectView. However, this should be used with caution. It utilizes a private UIKit API to do its magic; submitting this code to the App Store adds the risk of being rejected!

0
votes

you can try Following.

yourView.backgroundColor = UIColor.clear
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.light)   // Or   UIBlurEffectStyle.dark    
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = viewAdvancefilter.blurredView.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
yourView.addSubview(blurEffectView)
0
votes

You could try to use UIToolbar.
It has the same blur effect as UINavigationBar and UITabBar that cannot be achieved with UIBlurEffect.