Skip to content

Instantly share code, notes, and snippets.

@tixster
Created August 14, 2022 17:56
Show Gist options
  • Select an option

  • Save tixster/ac792671e614c8c58c19884a8b36b0f8 to your computer and use it in GitHub Desktop.

Select an option

Save tixster/ac792671e614c8c58c19884a8b36b0f8 to your computer and use it in GitHub Desktop.
import SwiftUI
public class UIBackdropView: UIView {
override class public var layerClass: AnyClass {
return NSClassFromString("CABackdropLayer") ?? CALayer.self
}
}
public struct Backdrop: UIViewRepresentable {
public func makeUIView(context: Context) -> UIBackdropView {
UIBackdropView()
}
public func updateUIView(_ uiView: UIBackdropView, context: Context) { }
}
public struct Blur: View {
public var radius: CGFloat = 3
public var opaque: Bool = false
public var body: some View {
Backdrop()
.blur(radius: radius, opaque: opaque)
}
}
public extension View {
func backgroudBlur(radius: CGFloat = 3, opaque: Bool = false) -> some View {
self
.background(Blur(radius: radius, opaque: opaque))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment