c# - 使用 MonoTouch.Dialog 时更改 TabBarController 和 NavigationController

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

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

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

    }

我的一个 Controller 的示例

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

我应该在哪里改变颜色?让我改变顶部和底部?

最佳答案

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

例如调用这个

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

来自您的FinishedLaunching将使所有导航栏具有黑色背景,甚至是来自MonoTouch.Dialog的导航栏(而不是默认的蓝色)和具有绿色背景(而不是黑色)的选项卡栏。

注释 1: 在 iOS5 之前,您需要为每个控件设置 *Color 属性(这不太有趣,因为您并不总是有权访问它们)。

注释 2: 您创建了 UIWindow 的新实例两次,即在 FinishedLaunching 中调用以下内容创建选项卡

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

关于c# - 使用 MonoTouch.Dialog 时更改 TabBarController 和 NavigationController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9442442/

相关文章:

c# - 我可以使用什么技术为我的 C# 应用程序编写一个 View ?

ios - 在保存到目录之前在 UIImage 中调整图像大小

c# - 呈现 ModalView 时出现 NSInvalidArgumentException

android - 我如何托管可以在浏览器、Android 和 iOS 上由共享云上相同数据库的用户使用的 Web 服务?

android - iphone 和 android 上的磁盘访问写入/更新数据的速度有多快

ios - UITableView.SizeThatFits() 的尺寸错误

c# - 在 MonoTouch 中有一个 NSFetchRequest 和一个 NSPredicate 支持

javascript - OnServerChange 事件未触发

c# - 可空变量类型 - .value 成员

c# - Python 到 c# 减少函数理解