Rajzer
Rajzer

Reputation: 1286

Xamarin.Forms 5.0 NavBar BackgroudColor not changing on IOS

I have this code in AppDelegate.cs function FinishedLaunching :

 UINavigationBar.Appearance.BackgroundColor= Color.FromHex("07987f").ToUIColor(); 
 UINavigationBar.Appearance.BarTintColor = Color.FromHex("07987f").ToUIColor();
 UINavigationBar.Appearance.TintColor = Color.White.ToUIColor();
 UINavigationBar.Appearance.TitleTextAttributes = new UIStringAttributes { ForegroundColor = UIColor.White };

Before update Xamarin.Forms 4.8 to 5.0 this code worked for every navbar but now only show white color. TintColor and TextColor working fine. What should be the problem? IMAGE: enter image description here

Upvotes: 1

Views: 599

Answers (3)

J Greenwood
J Greenwood

Reputation: 1

For iOS 15, there is a known issue with the navbar color. You can override the default behavior by setting the color in your AppDeligate.cs file. This will affect every page:

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    //A bug with iOS 15 results in the backgorund color not being set on the main appshell nav so we need to force it here
    var appearance = new UINavigationBarAppearance()
    {
         BackgroundColor = UIColor.FromRGB(144, 191, 110),
         ShadowColor = UIColor.FromRGB(144, 191, 110),
    };

    UINavigationBar.Appearance.StandardAppearance = appearance;
    UINavigationBar.Appearance.ScrollEdgeAppearance = appearance;
}
        

Both the StandardAppearance and the ScrollEdgeAppearence must be set the same. More info: https://developer.apple.com/forums/thread/682420

Upvotes: 0

nevermore
nevermore

Reputation: 15786

You can set the color in Xamarin.forms when creating the NavigationPage:

MainPage = new NavigationPage(new MainPage()) { 
    BackgroundColor = Color.FromHex("07987f"), 
    BarBackgroundColor = Color.FromHex("07987f") 
};

I also see a thread in Github about this issue and you can wait the response there:

UINavigationBar BackgroundColor can no longer be changed

Upvotes: 1

Ivan I
Ivan I

Reputation: 9990

You should try to specify it with Xamarin.Forms, using NavigationPage class.

It is certain that some code applies the color AFTER your code and thus you need to either disable it (if possible) or override it further down the line (as described above).

Upvotes: 0

Related Questions