Fix UIVisualEffectView extra light blur being gray on white background Fix UIVisualEffectView extra light blur being gray on white background ios ios

Fix UIVisualEffectView extra light blur being gray on white background


As far as I know the additional tint is a built-in feature of the UIVisualEffectView class. If you examine the view hierarchy with Xcode, you can see that there are two default subviews in the visual effect view instance: UIVisualEffectBackdropView and UIVisualEffectSubview. (I assume that these are private classes.) If you inspect UIVisualEffectSubview you can see that it has a background color which causes the unwanted tint that you've noticed.

I am not sure if there's an officially supported way to remove it, but you can modify this background color by filtering to the name of the private subview:

if let vfxSubView = visualEffectView.subviews.first(where: {    String(describing: type(of: $0)) == "_UIVisualEffectSubview"}) {    vfxSubView.backgroundColor = UIColor.white.withAlphaComponent(0.7)}

(Swift 5 compatible)

The default tint is around 70% opacity, so the easiest is to use the target background color with 0.7 alpha component.

I've also noticed that this might reset to the default value if the visual effect contains a custom subview. If I add this same snippet to the viewDidLayoutSubviews function of the view's controller, then it will keep the custom background color even after the built-in subview is updated.

Here's an example with a dark blur effect style. The top part shows the default tint and the bottom version has a custom black background color with 70% opacity.

enter image description here


If you just want the blur and your blurred view is gonna be stationary, you could use the UIImageEffects class and change the tintColor to a "full" white:

- (UIImage *)applyExtraLightEffect{    UIColor *tintColor = [UIColor colorWithWhite:0.97 alpha:0.82];    return [self applyBlurWithRadius:20 tintColor:tintColor saturationDeltaFactor:1.8 maskImage:nil];}

As far as I know you can't change it in the UIVisualEffectView.


You can try :

var visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .Light))    visualEffectView.frame = imageView.boundsimageView.addSubview(visualEffectView)