2

I am trying to change the the colour of a navigation bar controller and also a tab bar controller

I am using the monotouch.dialog to build my application and have the following code

    public partial class AppDelegate : UIApplicationDelegate
{
    // class-level declarations
    UIWindow window;

    //
    // This method is invoked when the application has loaded and is ready to run. In this 
    // method you should instantiate the window, load the UI into it and then make the window
    // visible.
    //
    // You have 17 seconds to return from this method, or iOS will terminate your application.
    //
    public override bool FinishedLaunching (UIApplication app, NSDictionary options)
    {
        // create a new window instance based on the screen size
        window = new UIWindow (UIScreen.MainScreen.Bounds);

        // If you have defined a view, add it here:
        // window.AddSubview (navigationController.View);
        CreateTabs();
        // make the window visible
        window.MakeKeyAndVisible ();

        return true;
    }

    protected void CreateTabs()
    {
        window = new UIWindow (UIScreen.MainScreen.Bounds);

    var nav = new UITabBarController ();
    nav.ViewControllers = new UIViewController [] {
        new HomeController("Home"),
        new WhereToUseController(),
        new TransactionsController(),
        new SettingsController()
    };

    //  nav.TabBarController.TabBar.BackgroundColor = UIColor.Green;
    nav.CustomizableViewControllers = new UIViewController [0];
    window.RootViewController = nav;
// window.BackgroundColor =  UIColor.Orange;        
        window.MakeKeyAndVisible ();

    }

An example of one of my controllers

    public override void LoadView ()
    {
        base.LoadView ();
    //TableView.BackgroundColor = UIColor.Clear;
  //  ParentViewController.View.BackgroundColor = UIColor.Red;
    }

    public HomeController (string s)
    {

         TabBarItem = new UITabBarItem (s, null, 1);

        var root = new RootElement (s) {


            new Section () {
                new UIViewElement("My Caption:", view, false),
                new StyledStringElement("Hello","somevalue"),
                new StringElement ("Welcome back Shane"),
                    new ImageElement(new UIImage("Images/QR.png")),
            }
        };

        PushViewController (new DialogViewController (root), false);
    }

Where am I meant to be changing the colour? to allow me to change the top and bottom?

poupou
  • 43,413
  • 6
  • 77
  • 174
Diver Dan
  • 9,953
  • 22
  • 95
  • 166

1 Answers1

2

If you target iOS 5 (and more recent versions) then you should look at the new UIAppearance feature. It will allow you to set the look of all types of control for your application (once, not for each that you create).

E.g. calling this

 UINavigationBar.Appearance.TintColor = UIColor.Black;
 UITabBar.Appearance.TintColor = UIColor.Green;

from your FinishedLaunching will make all navigation bar with a black background, even those from MonoTouch.Dialog (instead of the default blue) and the tab bar with a green background (instead of black).

note 1: before iOS5 you'll need to set the *Color properties for each control (which is less fun since you don't always have access to them).

note 2: you're creatine a new instance of UIWindow two times, i.e. the following is called in FinishedLaunching and CreateTabs

  window = new UIWindow (UIScreen.MainScreen.Bounds);
poupou
  • 43,413
  • 6
  • 77
  • 174