Skip to content

Instantly share code, notes, and snippets.

@cmmartin
Created January 22, 2016 03:34
Show Gist options
  • Save cmmartin/c74ad6ffd2685ca4cf5b to your computer and use it in GitHub Desktop.
Save cmmartin/c74ad6ffd2685ca4cf5b to your computer and use it in GitHub Desktop.
Apple a UIVibrancyEffect to an iOS navigation bar
override func viewWillAppear(animated: Bool) {
// Make the bar actually transparent by setting an empty image as the background
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.translucent = true
var bounds = (self.navigationController?.navigationBar.bounds)!
// make it cover the status bar by offseting y by -20
bounds.offsetInPlace(dx: 0.0, dy: -20.0)
bounds.size.height = bounds.height + 20.0
// set the background to a UIVisualEffectView
let visualEffectView = BlurredBackgroundView(frame: bounds)
visualEffectView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
self.navigationController?.navigationBar.insertSubview(visualEffectView, atIndex: 0)
}
@cmmartin
Copy link
Author

BlurredBackgroundView is a UIVisualEffectView like...
https://gist.github.com/cmmartin/c904e5a90ba89807c9bc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment