eestein
eestein

Reputation: 5114

How to change the navigation bar title color on Xamarin.iOS

I'd like to know how to change the navigation bar title's color. This is how it should be done in swift:

UINavigationBar.appearance().titleTextAttributes =
                             [NSForegroundColorAttributeName : UIColor.white]

How can I replicate that behavior using Xamarin.iOS?

I tried working with the answers here What to use for AttributeName in Xamarin Mac but I couldn't make it work because it could not convert from NSMutableAttributedString to UIStringAttributes.

Thanks.

Upvotes: 5

Views: 3887

Answers (3)

Sergey Ivanov
Sergey Ivanov

Reputation: 137

In addition to the answer by @eestein I'd like to add that this has to be done in the public override void ViewWillAppear - I've tried to change styles of the NavigationBar in the ViewDidAppear and had many hours of fun, frustration and despair figuring out why something works for others but not for me and if it's not working - then what will :)))

Upvotes: 0

fred
fred

Reputation: 427

void StyleNavBar()
    {
        this.NavigationController.NavigationBar.TitleTextAttributes = new UIStringAttributes()
        {
            ForegroundColor = UIColor.White,
            Font = UIFont.FromName("overpass-bold", 14)
        }; 
     }

Upvotes: 5

eestein
eestein

Reputation: 5114

This is how you do that:

UINavigationBar.Appearance.TitleTextAttributes = new UIStringAttributes
{
    ForegroundColor = UIColor.White
};

Upvotes: 11

Related Questions