Last active
August 9, 2023 08:47
-
-
Save KyleGoslan/4f0dd3a387c2387c31ccf823f2bb94d9 to your computer and use it in GitHub Desktop.
UIView extension to easily add and remove a blur (UIVisualEffectView)
This file contains 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
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() | |
} | |
} | |
} | |
} |
Thanks!
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
@hp0101 I've updated for Swift 4.2.