2012-02-25 26 views
2

我试图改变一个导航栏控制器的颜色,也是一个使用MonoTouch.Dialog

我使用monotouch.dialog建立我的应用和标签栏控制器时,更改TabBarController&NavigationController有以下代码

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(); 

    } 

我控制器

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); 
    } 

我在哪里意味着要改变颜色的一个例子吗?让我改变顶部和底部?

回答

2

如果您的目标iOS 5(和更新版本),那么你应该看看新的UIAppearance功能。它将允许您为应用程序设置所有类型控件的外观(一次,而不是每次创建的)。

E.g.调用此

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

将与黑色背景的所有导航栏,即使是那些从MonoTouch.Dialog(而不是默认的蓝色)和绿色背景(而不是黑色)标签栏。

注意1:在iOS5之前,您需要为每个控件设置*Color属性(因为您并不总是可以访问它们,所以它不那么有趣)。

注2:你肌酸UIWindow两次一个新的实例,即就是所谓的FinishedLaunchingCreateTabs

window = new UIWindow (UIScreen.MainScreen.Bounds); 
以下