Created
January 22, 2016 03:37
-
-
Save cmmartin/c904e5a90ba89807c9bc to your computer and use it in GitHub Desktop.
UIVisualEffectView with a background image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class BlurredBackgroundView: UIView { | |
let imageView: UIImageView | |
let blurView: UIVisualEffectView | |
override init(frame: CGRect) { | |
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Dark) | |
blurView = UIVisualEffectView(effect: blurEffect) | |
imageView = UIImageView(image: UIImage(name: "someBackgroundImage.jpg")) | |
super.init(frame: frame) | |
addSubview(imageView) | |
addSubview(blurView) | |
} | |
convenience required init(coder aDecoder: NSCoder) { | |
self.init(frame: CGRectZero) | |
} | |
override func layoutSubviews() { | |
super.layoutSubviews() | |
imageView.frame = bounds | |
blurView.frame = bounds | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment