【问题标题】:Changing TabBarController & NavigationController when using MonoTouch.Dialog使用 MonoTouch.Dialog 时更改 TabBarController 和 NavigationController
【发布时间】:2012-02-25 08:13:23
【问题描述】:

我正在尝试更改导航栏控制器和标签栏控制器的颜色

我正在使用 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);
    }

我打算在哪里改变颜色?让我改变顶部和底部?

【问题讨论】:

    标签: c# ios xamarin.ios monodevelop monotouch.dialog


    【解决方案1】:

    如果您的目标是 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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-22
      • 1970-01-01
      相关资源
      最近更新 更多