SomaMan
SomaMan

Reputation: 4164

MvvmCross UINavigationController customise navigationBar

Further to my experiences with MvvmCross, I've managed to build an app for iPhone which starts with a TabBarController. I can also successfully navigate within each tab to deeper levels. The problems start when I want to customise the navigationBar on the deeper levels - setting the backButton colours, etc. The code I use for navigation is the standard viewModel code -

this.RequestNavigate<InJourneyViewModel>();

…which works fine, but I can't do anything to the navigated-to view's navBar, other than set its title.

Any thoughts or advice appreciated!

Upvotes: 2

Views: 3010

Answers (1)

Stuart
Stuart

Reputation: 66882

I think it might help if you posted some more of your code that is failing.

My suspicion is that the problem is a more generic Cocoa, MonoTouch and/or backbarbutton problem.

I've just played with the ViewDidLoad code in MapView.cs in https://github.com/slodge/MvvmCross/tree/master/Sample%20-%20CirriousConference/Cirrious.Conference.UI.Touch

At the end of this, I was able to add some bar button changes like:

        var leftButton = new UIBarButtonItem("FooBar", UIBarButtonItemStyle.Bordered, null);
        leftButton.TintColor = UIColor.Green;
        NavigationItem.SetLeftBarButtonItem(leftButton, false);
        NavigationItem.RightBarButtonItem.TintColor = UIColor.Red;

Which resulted in:

four

Alternatively, by placing code in the WelcomeView:

        var leftButton = new UIBarButtonItem("FooBar", UIBarButtonItemStyle.Bordered, null);
        leftButton.TintColor = UIColor.Green;
        NavigationItem.BackBarButton = leftButton;

Then I succeed in achieving:

three

Alternatively, by using code like:

        UIBarButtonItem.AppearanceWhenContainedIn(typeof(UINavigationBar)).TintColor = UIColor.Blue;

Then this enabled me to customise all the navigation bar buttons like:

two


At one point, I also managed to achieve:

one

... but sadly I've genuinely no idea which code combo gave me that! If your problem is with back buttons in particular, then I think you will need to dig around other questions and/or post some code and hope someone can help - there's lots of posts about how to do this, but I can't quite figure out what they all mean for MonoTouch - e.g. Separate title in NavigationBar and navigation buttons

Upvotes: 1

Related Questions