Hide StatusBar for specific ContentPage

前端 未结 3 475
星月不相逢
星月不相逢 2021-02-03 13:48

I\'m creating an app where I want to hide the statusbar on a specific page. In my example it\'s a ContentPage. I found several samples where the info.plist is used to hide it, b

3条回答
  •  攒了一身酷
    2021-02-03 14:24

    You could use a PageRenderer for this. Here is an example:

    public class NoStatusBarPageRenderer : PageRenderer
    {
        public NoStatusBarPageRenderer()
        {
        }
    
        public override void ViewWillAppear(bool animated)
        {
            UIApplication.SharedApplication.SetStatusBarHidden(true, UIStatusBarAnimation.Fade);
    
            base.ViewWillAppear(animated);
        }
    
        public override void ViewDidDisappear(bool animated)
        {
            UIApplication.SharedApplication.SetStatusBarHidden(false, UIStatusBarAnimation.Fade);
    
            base.ViewDidDisappear(animated);
        }
    }
    

    Then, for each page that you want to have the status bar hidden, add an attribute to use this renderer on that page.

    [assembly: ExportRenderer(typeof(MyContentPage), typeof(NoStatusBarPageRenderer))]
    

提交回复
热议问题