Skip to content

Instantly share code, notes, and snippets.

@e23z
Last active July 26, 2017 14:50
Show Gist options
  • Save e23z/f9b9c6383b6221e3c0dbea90b72b9b70 to your computer and use it in GitHub Desktop.
Save e23z/f9b9c6383b6221e3c0dbea90b72b9b70 to your computer and use it in GitHub Desktop.
[Blurred Overlay] How to apply a blurred overlay to a view. #swift #ios #ui
//only apply the blur if the user hasn't disabled transparency effects
if !UIAccessibilityIsReduceTransparencyEnabled() {
self.view.backgroundColor = UIColor.clear
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
//always fill the view
blurEffectView.frame = self.view.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.view.addSubview(blurEffectView) //if you have more UIViews, use an insertSubview API to place it where needed
} else {
self.view.backgroundColor = UIColor.black
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment