Home > AI > IOS > SwiftUI >

UIBlurEffect

An object that applies a blurring effect to the content layered behind a visual effect view.

Example:

struct ContentView: View {

    var body: some View {
        MyView()
    }
}


struct MyView: UIViewRepresentable {
    func makeUIView(context: Context) -> some UIView {
        let view = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
        
        let imageView = UIImageView(image: UIImage(named: "apple"))
        imageView.frame = view.bounds
        imageView.contentMode = .scaleAspectFit
        view.addSubview(imageView)

        let blurEffect = UIBlurEffect(style: .dark)
        let blurredEffectView = UIVisualEffectView(effect: blurEffect)
        blurredEffectView.frame = imageView.bounds
        view.addSubview(blurredEffectView)
        
        return view
        
    }
    
    func updateUIView(_ uiView: UIViewType, context: Context) {
        
    }
}

Leave a Reply