Search code examples
iosswiftuitableviewbluruiblureffect

TableView with image background and blur effect - swift


I have a little problem: I'd like to set an image to background in a TableViewController. I tried this:

class SquadreController: UITableViewController {

    override func viewDidLoad()
    {
        super.viewDidLoad()

        var sfondo = UIImage(named: "sfondo")
        self.view.backgroundColor = UIColor(patternImage: sfondo!)

    }

Then I give the blur effect to the view, like this:

let blur = UIBlurEffect(style: UIBlurEffectStyle.Light)
let blurView = UIVisualEffectView(effect: blur)
blurView.frame = self.view.bounds
view.addSubview(blurView)

But there is a big problem. I'm working in a TableView and the TableView, TableCell, NavigationItem, etc. have all disappeared after I apply the blur. Can someone help me?

Thanks a lot!


Solution

  • Try using view.insertSubView(blurView, atIndex: 0) instead of view.addSubview(blurView) as! UIImageView