0

I am trying out making my first table based app.. However it wont change the color of the title on the navbar.

I tried this code, but it does not seem to work:

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

Also I made a LeftBarButtonItem, however I can't see it, but when clicked where it should be, it does do what it should..

    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);
    };
Emil Elkjær
  • 685
  • 1
  • 9
  • 31

2 Answers2

2

To change the color of the title in navigation bar check out this answer.

And for the custom buttons in the navigation bar check out this answer

If you have any problems translating objective-c to C#, write a comment.

EDIT

In ViewDidLoad of your ViewController add:

// 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;
Community
  • 1
  • 1
Norbert Szenasi
  • 993
  • 10
  • 24
0

The properties you are looking for are probably:

this.NavigationController.NavigationBar.TintColor;
this.NavigationController.NavigationBar.BarTintColor; //this one is iOS7 only
Stephane Delcroix
  • 16,134
  • 5
  • 57
  • 85
  • I've changed the color of the bar itself, however I am looking to change the text color of the title(ie. News), and also I added a left button instead of the back button, but it does not show up. – Emil Elkjær Nov 18 '13 at 14:21