Skip to content

Commit

Permalink
Add FXIOS-4565 [v104] Add shortcut methods for blurring a UIView (moz…
Browse files Browse the repository at this point in the history
  • Loading branch information
adudenamedruby authored Jul 19, 2022
1 parent 75099df commit 4c0fdc1
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Client/Extensions/UIViewExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,35 @@ extension UIView {
}
return nil
}

/// Shortcut to set the view's background colour to `.clear`, set the view's
/// `clipsToBounds` property set to true, and then add a blur effect on the view,
/// using the desired blur style.
///
/// - Parameter style: The strength of the blur desired
func addBlurEffectWithClearBackgroundAndClipping(using style: UIBlurEffect.Style) {
self.clipsToBounds = true
self.backgroundColor = .clear
self.addBlurEffect(using: style)
}

/// Shortcut to set a blur effect on a view, given a specified style of blur desired.
///
/// - Parameter style: The strength of the blur desired
func addBlurEffect(using style: UIBlurEffect.Style) {
let blurEffect = UIBlurEffect(style: style)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.translatesAutoresizingMaskIntoConstraints = false
self.addSubview(blurEffectView)
self.sendSubviewToBack(blurEffectView)

NSLayoutConstraint.activate([
blurEffectView.leadingAnchor.constraint(equalTo: self.leadingAnchor),
blurEffectView.trailingAnchor.constraint(equalTo: self.trailingAnchor),
blurEffectView.topAnchor.constraint(equalTo: self.topAnchor),
blurEffectView.bottomAnchor.constraint(equalTo: self.bottomAnchor)
])
}
}

protocol CardTheme {
Expand Down

0 comments on commit 4c0fdc1

Please sign in to comment.