1

I am trying to blur the status bar depending on the background like it works when we pull down the status bar. like it is see through

        let statusBarFrame = UIApplication.shared.statusBarFrame
        let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .light))
        visualEffectView.frame = statusBarFrame
        view.addSubview(visualEffectView)

I have tried all styles but it does change to translucent even I tried from storyboard effect shows in the storyboard but not in simulator even my Reduce Transparency is also turned on

enter image description here

I want to achive this in the stausbar

enter image description here

but it only gives a white bar

1 Answers1

0

You can get your statusBar view by following code, then try add to visual effect like here

     let statWindow = UIApplication.shared.value(forKey:"statusBarWindow") as! UIView
        let statusBar = statWindow.subviews[0] as UIView
        statusBar.backgroundColor = UIColor(red: 213 / 255.0, green: 0 / 255.0, blue: 0 / 255.0, alpha: 0.7)

OR

extension UINavigationBar {
    func installBlurEffect() {
        isTranslucent = true
        setBackgroundImage(UIImage(), for: .default)
        let statusBarHeight: CGFloat = UIApplication.shared.statusBarFrame.height
        var blurFrame = bounds
        blurFrame.size.height += statusBarHeight
        blurFrame.origin.y -= statusBarHeight
        let blurView  = UIVisualEffectView(effect: UIBlurEffect(style: .light))
        blurView.isUserInteractionEnabled = false
        blurView.frame = blurFrame
        blurView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        addSubview(blurView)
        blurView.layer.zPosition = -1
    }
}

Usage

navigationController?.navigationBar.installBlurEffect()
B K.
  • 534
  • 5
  • 18
  • 1
    bro, I am not trying to change the text color of the status bar I am trying to change the background to blur view as we see in a pull-up and down bar view in iPhone I am not using the navigation bar I don't know how to attach an image so I can show – Meet Ios Developer May 16 '19 at 09:54
  • Edited my answer, please check – B K. May 16 '19 at 09:56
  • no, it does not work the link you shared I wan that exact thing only in the status bar only I am not using nav bar – Meet Ios Developer May 16 '19 at 10:07