This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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