C# Monotouch/Xamarin - Replace Entire Tab Button W

2019-08-12 14:14发布

问题:

Is it possible to replace the entire tab button for each tab with a different image in the UITabBarController?

INSTEAD OF THIS - (Standard Default Tab Controller Appearance)

DO THIS - (Custom Tab Controller Appearance Using Images)

How would I go about doing this?

Customization of the UITabBarController seems pretty nasty. You can change the tint colour, but that affects the colour of the tab image in it's various selected/not-selected states....

回答1:

It's not obvious. But here's how to use full colored images and optionally omit the text label.

var tabBarItem = new UITabBarItem("Item Text", null, 1);
tabBarItem.SetFinishedImages(UIImage.FromBundle("./Images/addexpense.png"), UIImage.FromBundle("./Images/addexpense.png"));

var controllerToAdd = new UIViewController()
{
    TabBarItem = tabBarItem
};

tabBarController.SetViewControllers(new UIViewController[]
{
 controllerToAdd
};

The result can then look something like this (of course you can also get rid of the text completely by omitting the "Item Text" shown in my example):