Skip to content

Instantly share code, notes, and snippets.

@jfversluis
Created March 3, 2022 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfversluis/b63f0825a4184695733bb090dc85adcf to your computer and use it in GitHub Desktop.
Save jfversluis/b63f0825a4184695733bb090dc85adcf to your computer and use it in GitHub Desktop.
public class PageRenderer : Xamarin.Forms.Platform.iOS.PageRenderer
{
protected override void OnElementChanged(Xamarin.Forms.Platform.iOS.VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if(e.OldElement != null || Element == null)
{
return;
}
try
{
UpdateStatusBarColor();
}
catch(Exception ex)
{
Debug.WriteLine($"Error: {ex.Message}");
}
}
private void UpdateStatusBarColor()
{
var bar = GetStatusBar();
bar.BackgroundColor = ColorConverters.FromHex("#fd7b38").ToPlatformColor();
}
private UIView GetStatusBar()
{
UIView statusBar;
if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
{
int tag = 123; // Customize this tag as you want so we don't create it over and over
UIWindow window = UIApplication.SharedApplication.Windows.FirstOrDefault();
statusBar = window.ViewWithTag(tag);
if (statusBar == null)
{
statusBar = new UIView(UIApplication.SharedApplication.StatusBarFrame);
statusBar.Tag = tag;
statusBar.BackgroundColor = UIColor.Red; // Customize the view
window.AddSubview(statusBar);
}
}
else
{
statusBar = UIApplication.SharedApplication.ValueForKey(new NSString("statusBar")) as UIView;
}
return statusBar;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment