Skip to content

Instantly share code, notes, and snippets.

@wata
Created June 7, 2018 14:33
Show Gist options
  • Select an option

  • Save wata/aa00f713e0a7e8b359318062ad840a38 to your computer and use it in GitHub Desktop.

Select an option

Save wata/aa00f713e0a7e8b359318062ad840a38 to your computer and use it in GitHub Desktop.
import UIKit
class BlurredImageView: UIImageView {
private let blurEffectView: UIVisualEffectView = {
let blurEffect = UIBlurEffect(style: .light)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
return blurEffectView
}()
override var image: UIImage? {
didSet {
guard self.image != nil else {
self.blurEffectView.removeFromSuperview()
return
}
self.blurEffectView.frame = self.bounds
self.addSubview(self.blurEffectView)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment