使ViewController背景模糊

时间:2019-01-07 12:00:37

标签: swift

我得到的UIViewController包含自定义导航栏和一个UITableView 我正在尝试使所有视图背景模糊,以便图标和标签以及信息显示在模糊效果上方 我尝试过,但是模糊效果会应用到图标和信息上

viewWillAppear中的此代码

//Background
ChatRoomTable.backgroundColor = .clear
let backgroundImage = UIImage(named: "16.png")
let imageView = UIImageView(image: backgroundImage)
ChatRoomTable.backgroundView = imageView
ChatRoomTable.tableFooterView = UIView(frame: CGRect.zero)
ChatRoomTable.sectionIndexColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.6715271832)
let blurEffect = UIBlurEffect(style: .dark)
let blurView = UIVisualEffectView(effect: blurEffect)
blurView.frame = self.view.bounds
view.addSubview(blurView)

更新

current image

我想要这样的背景,并且上面显示的所有内容

enter image description here

2 个答案:

答案 0 :(得分:0)

尝试像Content View那样将图像添加到blurView的{​​{1}}

答案 1 :(得分:0)

@SemarY I got your bug you added image you at wrong place so let me give you code which will help you for your desire output.

//Background
ChatRoomTable.backgroundColor = .clear
ChatRoomTable.tableFooterView = UIView(frame: CGRect.zero)
ChatRoomTable.sectionIndexColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.6715271832)
let backgroundImage = UIImage(named: "16.png")
let imageView = UIImageView(image: backgroundImage)
imageView.frame = self.view bound
view.addSubView(imageView)
let blurEffect = UIBlurEffect(style: .dark)
let blurView = UIVisualEffectView(effect: blurEffect)
blurView.frame = self.view.bounds
view.addSubview(blurView)
self.bringSubviewToFront(ChatRoomTable)