1

I'm trying to style the UINavigationBar in Xamarin with MonoTouch. In the constructor of the UIViewController I tried the following:

//this.NavigationController.NavigationBar.TintColor = UIColor.Magenta;
UINavigationBar.Appearance.TintColor = UIColor.Yellow;

But if I try to run this in the simulator there is nothing changed. Where should I place this code? How do I use a RGB color (with UIColor.FromRGB (0, 127, 14)?) Is my code correct?

testing
  • 19,681
  • 50
  • 236
  • 417

4 Answers4

3

My Solution:

//AppDelegate.cs
public partial class AppDelegate : UIApplicationDelegate
{
    // class-level declarations
    UIWindow window;
    public static UIStoryboard Storyboard = UIStoryboard.FromName ("MainStoryboard", null);
    public static UIViewController initialViewController;

    // ...
    public override bool FinishedLaunching (UIApplication app, NSDictionary options)
    {
        window = new UIWindow (UIScreen.MainScreen.Bounds);
        initialViewController = Storyboard.InstantiateInitialViewController () as UIViewController;

        UINavigationBar.Appearance.SetTitleTextAttributes (
            new UITextAttributes () { TextColor = UIColor.FromRGB (0, 127, 14) });

        window.RootViewController = initialViewController;
        window.MakeKeyAndVisible ();
        return true;
    }
}
testing
  • 19,681
  • 50
  • 236
  • 417
3

Assuming that you're developing for iOS7 you need to set BarTintColor.

UINavigationBar.Appearance.BarTintColor = UIColor.Red;
UINavigationBar.Appearance.BarTintColor = UIColor.FromRGB(0, 127, 14);

see: How to change UINavigationBar background color from the AppDelegate

Put this code in AppDelegate.cs

Community
  • 1
  • 1
ihkawiss
  • 986
  • 3
  • 9
  • 25
0

Try this ..

NSDictionary *textTitleOptions = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor darkGrayColor], UITextAttributeTextColor, [UIColor whiteColor], UITextAttributeTextShadowColor, nil];
[[UINavigationBar appearance] setTitleTextAttributes:textTitleOptions];

Or you can refer more from IOS 7 Navigation Bar text and arrow color

Community
  • 1
  • 1
Vivek Shah
  • 430
  • 5
  • 22
0

You should specific the UIViewController, like:

viewController.navigationBar.tintColor = [UIColor yellowColor];

or in UIViewController:

self.navigationBar.tintColor = [UIColor yellowColor];
Martin Evans
  • 45,791
  • 17
  • 81
  • 97
7heaven
  • 797
  • 7
  • 16