NavigationController颜色和左键

时间:2013-11-16 23:00:57

标签: c# ios uinavigationcontroller xamarin.ios

我正在尝试制作我的第一个基于桌面的应用程序..但是它不会改变导航栏上标题的颜色。

我尝试了这段代码,但它似乎不起作用:

this.NavigationController.NavigationItem.TitleView.TintColor = UIColor.White;

我也制作了一个LeftBarButtonItem,但是我看不到它,但是当点击它应该的位置时,它确实做了它应该做的事情。

    this.NavigationController.NavigationItem.SetHidesBackButton (true, false);
    this.NavigationController.NavigationItem.LeftBarButtonItem = new UIBarButtonItem ();
    this.NavigationController.NavigationItem.LeftBarButtonItem.Style = UIBarButtonItemStyle.Plain;
    this.NavigationController.NavigationItem.LeftBarButtonItem.TintColor = UIColor.White;
    this.NavigationController.NavigationItem.LeftBarButtonItem.Title = "Tilbage";
    this.NavigationController.NavigationItem.LeftBarButtonItem.Clicked += (object sender, EventArgs e) => 
    {
        this.PerformSegue("fromItem", this);
    };

2 个答案:

答案 0 :(得分:2)

要更改导航栏中标题的颜色,请查看this answer

对于导航栏中的自定义按钮,请查看this answer

如果您在将Objective-c转换为C#时遇到任何问题,请撰写评论。

修改

ViewDidLoad ViewController添加:

// to change the appearance of the top navigation bar title
UITextAttributes attributes = new UITextAttributes();
    // set custom text color
attributes.TextColor = UIColor.FromRGB(255, 122, 122);
attributes.Font = UIFont.BoldSystemFontOfSize(20);
attributes.TextShadowColor = UIColor.FromRGBA(255, 255, 255, 128);
attributes.TextShadowOffset = new UIOffset(2, -2);

// to add buttons to navigation bar
UIBarButtonItem[] items = new UIBarButtonItem[]
{
    new UIBarButtonItem(
        NSBundle.MainBundle.LocalizedString("Tilbage", null),
        UIBarButtonItemStyle.Bordered,
        delegate(object sender, EventArgs e) {
            // do whatever you need
        Console.WriteLine("Custom button clicked!");
    })
};

NavigationController.NavigationBar.TintColor = UIColor.FromRGBA(255, 196, 196, 255);
NavigationController.NavigationBar.TopItem.Title = NSBundle.MainBundle.LocalizedString("LocalizedHeader", null);
// change appearance
NavigationController.NavigationBar.SetTitleTextAttributes(attributes);
// add buttons
NavigationItem.LeftBarButtonItems = items;

答案 1 :(得分:0)

您正在寻找的属性可能是:

this.NavigationController.NavigationBar.TintColor;
this.NavigationController.NavigationBar.BarTintColor; //this one is iOS7 only