Get nice, dark UIToolbar blur as in Facebook iOS 7 app

samvermette picture samvermette · Sep 22, 2013 · Viewed 10.2k times · Source

Does anyone know what Facebook uses for their blurred toolbar?

enter image description here

Now, I KNOW there are already countless threads about iOS 7 blur. They all come to these same solutions:

  1. Use a UIToolbar with translucent set to YES, and then set its barTintColor property. The problem with this approach is that it significantly increases the lightness of the color. This is the approach that AMBlurView uses. The nav bar in the Facebook app remains dark blue even when it's above white content. (with AMBlurView it becomes pastel blue)
  2. Render the underlying view's in a graphic context, then blur that context, output it as a UIImage and use that as background view, repeat 30 times per second. (which hurts performance pretty bad). This is the approach that FXBlurView uses. It doesn't seem like Facebook is using that either.

I've read at length in the Apple Dev Forums and it seems like this is a technical challenge even for Apple engineers. With Facebook nailing the real-time blur with something else than the two approaches I described. Any idea?

Answer

sudo rm -rf picture sudo rm -rf · Sep 22, 2013

Apparently the trick here is to insert the translucent layer as a sublayer of the navigation bar. I take no credit for finding this, and the following snippet has been taken from this gist.

UIColor *barColour = [UIColor colorWithRed:0.13f green:0.14f blue:0.15f alpha:1.00f];

UIView *colourView = [[UIView alloc] initWithFrame:CGRectMake(0.f, -20.f, 320.f, 64.f)];
colourView.opaque = NO;
colourView.alpha = .7f;
colourView.backgroundColor = barColour;

self.navigationBar.barTintColor = barColour;

[self.navigationBar.layer insertSublayer:colourView.layer atIndex:1];