iOS Question Change statusbar color ios > 13

Lucas Siqueira

Active Member
Licensed User
Longtime User
I'm trying to change the color of the statusbar in b4i, but I'm getting the following error, which ends up closing the application.

Code:
Dim no As NativeObject = Main.App
no.GetField("statusBar").SetField("backgroundColor", no.ColorToUIColor(cor_barra_status))

B4X:
App called -statusBar or -statusBarWindow on UIApplication: this code must be changed as there's no longer a status bar or status bar window. Use the statusBarManager object on the window scene instead.

Apparently this statusBar is no longer supported in iOS 13, I found this code in Swift and I can't implement it in b4i. Can anyone help me set the status bar to the desired color? or help me implement this swift code in my code?






Objective-C:
var statusBarTagNumber = 1
if #available(iOS 13.0, *) {
    let app = UIApplication.shared
    let statusBarHeight: CGFloat = app.statusBarFrame.size.height
    
    for subview in view.subviews {
        if subview.tag == statusBarTagNumber {
            subview.backgroundColor = backgroundColor
            return
        }
    }

    let statusbarView = UIView()
    statusbarView.tag = statusBarTagNumber
    statusbarView.backgroundColor = UIColor.red
    view.addSubview(statusbarView)
 
    statusbarView.translatesAutoresizingMaskIntoConstraints = false
    statusbarView.heightAnchor
        .constraint(equalToConstant: statusBarHeight).isActive = true
    statusbarView.widthAnchor
        .constraint(equalTo: view.widthAnchor, multiplier: 1.0).isActive = true
    statusbarView.topAnchor
        .constraint(equalTo: view.topAnchor).isActive = true
    statusbarView.centerXAnchor
        .constraint(equalTo: view.centerXAnchor).isActive = true
 
} else {
    let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView
    statusBar?.backgroundColor = UIColor.red
}
 
Top