views:

415

answers:

1

Try as I might, I cannot get this to work. Here is my latest attempt. Can someone clue me in as to why this does not work?

In a method which is called by my view controller's init method:

UIImage *image = [UIImage imageNamed: @"window22.png"];
UITabBarItem *item = [[UITabBarItem alloc] initWithTitle: @"Some Title" image: image tag: 0];
self.tabBarItem = item;

All it does is put a big square where the image should be. The title in the tab bar remains the same as the view controller's title.

Everything is being instantiated programmatically here, including the tab bar controller.

A: 

According to the docs, the tabBarItem will be instantiated automatically- you don't need to create it yourself. When I've set the title and image in the tabBar for a view controller, I've used

self.tabBarItem.image = [UIImage imageNamed:imageName];
Rob Lourens
I just tried that . . . and it still gives me that blue square!Could there be something wrong with my image? It is a 22x22 PNG file, mostly white, with a little bit of black. I also tried other dimensions like 30x30 with the same result.When I put my image into a UIImageView, it displays just fine.
William Jockusch
Are you using transparency in the image? The actual colors of your image will be ignored, it only takes the alpha channel of the image into account. Google around for some examples.
Rob Lourens
I'm pretty sure you nailed my difficulty . . . thanks! Now I have to figure out how to generate images in the alpha channel . . .
William Jockusch