I'm having issues getting images to show on the tab bar.
I have a project in MonoTouch that uses a UITabBarController
as the host of the app. For each tab item I have a UINavigationController
.
In ViewDidLoad
of my UITabBarController
class:
ViewControllers = new UIViewControllers[]
{
myNavController1,
myNavController2,
myNavController3
};
ViewControllers[0].TabBarItem =
new UITabBarItem (UITabBarSystemItem.Search, 1);
ViewControllers[1].TabBarItem =
new UITabBarItem ("Foo", UIImage.FromFile ("Resources/foo.png"), 2);
ViewControllers[2].TabBarItem =
new UITabBarItem ("Foo", UIImage.FromFile ("Resources/foo.png"), 3);
The first tab bar item works fine, it says Search and you see the system image for search. However, the other two only show the title and not the image. What do I need to do to get the image to correctly load?
Thanks.
Seems I found the answer surprisingly fast after posting this... >_<
I was loading the image from the Resources folder originally, this seems to be the issue. Having created a new folder called Images I then added a PNG file to this folder and tried loading the UIImage
image from there, everything works.
The build action is still "BundleResource" and it does not copy to the output dir (exactly the same property settings as the image in Resources folder).
So simply moving the image to a new folder and calling:
ViewControllers[1].TabBarItem =
new UITabBarItem ("Foo", UIImage.FromFile ("Images/foo.png"), 2);
Hope this helps someone, though most likely you'll just figure it out yourself haha