tags:

views:

111

answers:

4

I'm in the process of upgrading my iPhone app to high-res graphics, and I've run into some problems with older devices. The situation involves my UITabBar icons. Have a look:

alt text

The top screenshot looks correct. It was captured on the latest generation iPhone (new screen) running OS4. However, the second screenshot is completely wrong. The high-res icons are displaying at 100% size and are getting cropped. That second screenshot was taken from my second-gen iPod touch (old screen) running OS4.

So, I'm really confused here. I've read over Apple's documentation, and as far as I know I'm doing everything they require. Within my app bundle I have images named as:

Within interface builder, I have specified the low-res version of each image (the filename WITHOUT "@2x") to be used in the tab bar. If I understand iPhone documentation correctly, the device should automatically detect screen resolution and display the high-res version if available. So if anything, it almost seems like my iPod touch is incorrectly detecting its display resolution. Am I missing something here perhaps?

Any help or insight that can be offered would be appreciated! Thanks.

UPDATE:

No luck so far. I took the manual approach and added the following into the viewDidLoad command of my UITabBarController:

- (void)viewDidLoad {
    [super viewDidLoad];

    UITabBarItem *tab;
    UIViewController *item;

    tab = [[UITabBarItem alloc] initWithTitle:@"Featured" image:[UIImage imageNamed:@"tab-featured.png"] tag:0];
    item = [self.viewControllers objectAtIndex:0];
    item.tabBarItem = tab;
    [tab release];

    tab = [[UITabBarItem alloc] initWithTitle:@"Topics" image:[UIImage imageNamed:@"tab-topics.png"] tag:1];
    item = [self.viewControllers objectAtIndex:1];
    item.tabBarItem = tab;
    [tab release];

    tab = [[UITabBarItem alloc] initWithTitle:@"Video" image:[UIImage imageNamed:@"tab-video.png"] tag:2];
    item = [self.viewControllers objectAtIndex:2];
    item.tabBarItem = tab;
    [tab release];

    tab = [[UITabBarItem alloc] initWithTitle:@"Experts" image:[UIImage imageNamed:@"tab-experts.png"] tag:3];
    item = [self.viewControllers objectAtIndex:3];
    item.tabBarItem = tab;
    [tab release];

    tab = [[UITabBarItem alloc] initWithTitle:@"Events" image:[UIImage imageNamed:@"tab-events.png"] tag:4];
    item = [self.viewControllers objectAtIndex:4];
    item.tabBarItem = tab;
    [tab release];
}

This still produces the same result as above (large cut-off icons within the tab bar). Has anyone heard of issues with the UITabBar populating high-res icon pairs?

+1  A: 

As I understand it, the magic is in UIImage's imageNamed:, imageWithContentsOfFile: and initWithContentsOfFile: methods. Pass one of those an NSString literal without the "@2x" or the file extension, and it'll magically find the right version of the file for your device.

One implication of that is, the images for your tab bar items need to be set programmatically. It could be that IB isn't yet smart enough to write a nib that dynamically picks the image based on the device resolution. So try setting those images by hand in your -viewDidLoad method.

Dan Ray
Thanks for the response, unfortunately this still isn't doing the trick. I'll post my continued efforts into this thread.
Greg
I see the code you posted. Try leaving the ".png" off your filenames. As I understand it, those methods are going to take a base name as its NSString argument, and search for matching files with an optional "@2x" and a file extension.
Dan Ray
A: 

Were you able to solve this issue? I am having the exact same problem where for some reason when deploying my app on a iOS 3.1.3 device using hi-res images, in the exact same way you are, the 3.1.3 device is displaying the hi-res version of the png file and cropping it. thx

James
A: 

@James:

Yes, I was able to resolve this. It seemed to be an error with file references in XCode. I was running out of ideas, so I rolled back and started stripping out all @2x images from my app, just to get everything displaying correctly again with the low-res artwork. Once the app displayed proper size images again (albeit at low-resolution), then one by one I started adding the @2x images back in, waiting for something to break. It seemed to work fine the second time going in. Don't know why or what happened. The SDK just seemed to get some wires crossed as to what had happened.

Greg
A: 

Try omitting the .png file extension. Doing so triggers the OS to look for the low res files and @2x versions appropriately. This is documented in Apple's "Supporting High-Resolution Screens" overview.

Dan Harrelson
I had tried removing the extension early on with no success. It wasn't until I completely removed and relinked all the images that I got this issue straightened out.
Greg