Skip to content

Instantly share code, notes, and snippets.

@aheze
Created October 19, 2022 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aheze/2b53265eca22e6aae332132632e94505 to your computer and use it in GitHub Desktop.
Save aheze/2b53265eca22e6aae332132632e94505 to your computer and use it in GitHub Desktop.
/// Use UIKit blurs in SwiftUI.
struct VisualEffectView: UIViewRepresentable {
/// The blur's style.
public var style: UIBlurEffect.Style
/// Use UIKit blurs in SwiftUI.
public init(_ style: UIBlurEffect.Style) {
self.style = style
}
public func makeUIView(context: Context) -> UIVisualEffectView {
UIVisualEffectView()
}
public func updateUIView(_ uiView: UIVisualEffectView, context: Context) {
uiView.effect = UIBlurEffect(style: style)
}
}
/// usage:
VisualEffectView(.systemUltraThinMaterialDark)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment