2

Problem

Currently I'm developing an application and on iOS 16 the text color of the statusbar is often white while the background color of the customized header has a light color. In the code of the customized header there's a check that should set the correct UIStatusBarStyle based on the color of the header. When the header has a light color the text in the status bar should be black and the text should be white when the background color of the header is dark.

Since iOS 16 this logic doesn't work properly anymore and I've tried to fix it but it doesn't seem to work.

I don't have this behavior on simulators but I can reproduce it on an iPhone 12 with iOS 16.

The project uses Xamarin.iOS and C#.

What I tried

  • In the AppDelegate I've set the UIStatusBarStyle to DarkContent when the iOS is 16.
  • In the customized header I set the UIStatusBarStyle to DarkContent when the iOS is 16 with an if statement and a return. I also set the UIStatusBarStyle to DarkContent when the backgroundcolor of the header has a light color (fall back for other iOS versions).

Does anyone have the same behavior on iOS 16 with the UIStatusBarStyle? I only found one post about it and it's more for the end user and not for developers.

1 Answers1

0

I just had this same issue for iOS 16. Most of my views are dark so, I was wanting a status bar with white characters ( which was working fine using UIStatusBarStyle on iOS 15), regardless of user's Darkmode/LightMode settings. I was able to achieve it by setting .preferredColorScheme(.dark) where needed.

Edit: Just to clarify this though, .preferredColorScheme(.dark) will set your view to dark mode, so use only if that doesn't matter. As an alternative, you might have better luck playing around with things such as

.toolbarColorScheme(.dark, for: .navigationBar)
.toolbarBackground(.visible, for: .navigationBar)

in such cases where you are using a navigation bar. If you are not using one, you might be able to achieve your aim by setting .toolbarBackground(.hidden, for: .navigationBar) and playing around with it to whatever end. Hope this helps.

kensanwa
  • 11
  • 2
  • I'm using UIKit and your solution is for SwiftUI, am I correct? The issue I described still exists and I don't have a solution yet. – MobileAppDev Nov 16 '22 at 14:00