How do you get the status bar height in Xamarin.Forms? I use to just add 20 for spacing at the top for iOS, but that is not longer always the cause thanks to the iPhone X.
There is now a way to handle this built into Xamarin.Forms apparently:
Based on @DavidOrtinau feedback on twitter I ended up doing this in my page:
protected override void OnSizeAllocated(double width, double height)
base.OnSizeAllocated(width, height); //must be called
// if there is no NavigationBar then we need to fix the padding for iOS (because of iPhoneX)
var statusHeight = UIKit.UIApplication.SharedApplication.StatusBarFrame.Height;
this.Padding = new Thickness(0, statusHeight, 0, 0);
@JohannesHammersen Where do I put this for Xamarin.Forms?
I have a shared code project, so I've put in the code file of the page that needed the padding adjustment.
And I've wrapped it in a conditional compilation statement so that it will only be included in the iOS Version.
If you have a pcl project you would have to use Platform abstraction and move it in the iOS specific project, i guess.
Xamarin Inc., as a wholly-owned Microsoft subsidiary acting as a separate legal entity, adheres to the Microsoft Privacy Statement: Privacy & cookies