Skip to content

Instantly share code, notes, and snippets.

@dreymonde
Created March 30, 2023 07:14
Show Gist options
  • Save dreymonde/267f043b57debfcbef0b5ff4de173743 to your computer and use it in GitHub Desktop.
Save dreymonde/267f043b57debfcbef0b5ff4de173743 to your computer and use it in GitHub Desktop.
Custom drop-in UIImageView subclass that makes every image blurred with a specified visual effect. Swift, UIKit
final class BlurredImageView: UIImageView {
init(effect: UIVisualEffect? = UIBlurEffect(style: .regular)) {
super.init(frame: .zero)
blurView.effect = effect
addSubview(blurView)
}
var effect: UIVisualEffect? {
get { blurView.effect }
set { blurView.effect = newValue }
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private let blurView: UIVisualEffectView = {
let blurView = UIVisualEffectView()
return blurView
}()
override func layoutSubviews() {
super.layoutSubviews()
blurView.frame = bounds
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment