Created
March 30, 2023 07:14
-
-
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
This file contains hidden or 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
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