更改TabBarController&;使用MonoTouch.Dialog时的NavigationControl

本文关键字:MonoTouch Dialog 时的 NavigationControl 使用 TabBarController amp 更改 | 更新日期: 2023-09-27 18:25:41

我正在尝试更改导航栏控制器和选项卡栏控制器的颜色

我正在使用monotouch.dialog来构建我的应用程序,并有以下代码

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

我该在哪里换颜色?允许我更改顶部和底部?

更改TabBarController&;使用MonoTouch.Dialog时的NavigationControl

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

例如,调用此

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