locked
Can not be able to change the top bar background color! (IOS) RRS feed

  • Question

  • User367128 posted

    I have tried several ways: i have tried UINavigationBar.Appearance.BarTintColor = UIColor.FromHSB(351, 86, 95); and to add it in xaml but nothing seems to work any ideas?

    Sunday, August 5, 2018 12:55 AM

Answers

  • User369979 posted

    @arminmosaffaie If your page has been wrapped by a NavigationPage, then changing the navigation bar's BarTintColor will also be adapted by the status bar which you called top bar.

    But if your page doesn't have a navigation, this will not work. Try the code below in the AppDelegate:

    UIView statusBar = UIApplication.SharedApplication.ValueForKey(new NSString("statusBarWindow")).ValueForKey(new NSString("statusBar")) as UIView;
    if (statusBar.RespondsToSelector(new ObjCRuntime.Selector("setBackgroundColor:")))
    {
        statusBar.BackgroundColor = UIColor.FromHSB(351, 86, 95);
    }
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, August 6, 2018 2:40 AM

All replies

  • User369520 posted

    If you’re using a custom renderer, make sure the code is in the viewdidload event.

    Sunday, August 5, 2018 5:07 AM
  • User171749 posted

    Make sure you have this in your info.plist XAML <key>UIViewControllerBasedStatusBarAppearance</key> <false/> and you can set the color from Xamarin.Forms NavigationBar Property.

    CSHARP MainPage = new NavigationPage(new TestCameraPage()) { BarTextColor = Color.White };

    Sunday, August 5, 2018 8:47 AM
  • User369979 posted

    @arminmosaffaie If your page has been wrapped by a NavigationPage, then changing the navigation bar's BarTintColor will also be adapted by the status bar which you called top bar.

    But if your page doesn't have a navigation, this will not work. Try the code below in the AppDelegate:

    UIView statusBar = UIApplication.SharedApplication.ValueForKey(new NSString("statusBarWindow")).ValueForKey(new NSString("statusBar")) as UIView;
    if (statusBar.RespondsToSelector(new ObjCRuntime.Selector("setBackgroundColor:")))
    {
        statusBar.BackgroundColor = UIColor.FromHSB(351, 86, 95);
    }
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, August 6, 2018 2:40 AM