Add blurr to UIViewController view
extension UIViewController {
func addBlurredEffect(horizontalMargin: CGFloat, verticalMargin: CGFloat) {
// Set screen size to be arbitrary smaller than full screen
let screenBounds = UIScreen.mainScreen().bounds
let size = CGSize(width: screenBounds.width - horizontalMargin,
height: screenBounds.height - verticalMargin)
let centerPoint = CGPoint(x: screenBounds.width/2 - (size.width/2),
y: screenBounds.height/2 - (size.height/2))
view.frame = CGRect(origin: centerPoint, size: size)
// Init blurred view
let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .Light))
visualEffectView.frame = view.bounds
visualEffectView.autoresizingMask = .FlexibleWidth | .FlexibleHeight
visualEffectView.setTranslatesAutoresizingMaskIntoConstraints(true)
// Set Shadow properties
visualEffectView.layer.masksToBounds = false;
visualEffectView.layer.shadowOffset = CGSizeMake(1, 1)
visualEffectView.layer.shadowRadius = 10
visualEffectView.layer.shadowOpacity = 0.6
// Show it
view.addSubview(visualEffectView)
view.sendSubviewToBack(visualEffectView)
}
}