Skip to content

Instantly share code, notes, and snippets.

@cmmartin
Created January 22, 2016 03:37
Show Gist options
  • Save cmmartin/c904e5a90ba89807c9bc to your computer and use it in GitHub Desktop.
Save cmmartin/c904e5a90ba89807c9bc to your computer and use it in GitHub Desktop.
UIVisualEffectView with a background image
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