Skip to content

Instantly share code, notes, and snippets.

@KyleGoslan
Last active August 9, 2023 08:47
Show Gist options
  • Save KyleGoslan/4f0dd3a387c2387c31ccf823f2bb94d9 to your computer and use it in GitHub Desktop.
Save KyleGoslan/4f0dd3a387c2387c31ccf823f2bb94d9 to your computer and use it in GitHub Desktop.
UIView extension to easily add and remove a blur (UIVisualEffectView)
import UIKit
extension UIView {
func blurView(style: UIBlurEffect.Style) {
var blurEffectView = UIVisualEffectView()
let blurEffect = UIBlurEffect(style: style)
blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = bounds
addSubview(blurEffectView)
}
func removeBlur() {
for view in self.subviews {
if let view = view as? UIVisualEffectView {
view.removeFromSuperview()
}
}
}
}
@mutsm
Copy link

mutsm commented Aug 9, 2023

I replaced "self.subviews" with "view.subviews"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment