0

I have a TabBarController application that gets all the images from the web, including the icons for the tabBarController. What I want is that images look good when the device has retina display.

This is what I am doing:

  1. Resizing down images depending on the screen scale.
  2. Setting the view content scale: imageView.contentsScale = [UIScreen mainScreen].scale;

It is working fine for standard images with UIImageView, however I can not figure out how to do this for UITabBarItems, since I have no access to either the frame or the contentScale.

Any ideas?

Thanks!

Aklope
  • 1
  • 1
  • 1

3 Answers3

3

When creating the UIImage, you can set the scale of the image to 2.0 for retina size image resources. Here is a sample of how I did it:

NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
UIImage *image = [UIImage imageWithData:data];
CGImageRef cgimage = image.CGImage;
image = [UIImage imageWithCGImage:cgimage scale:2.0 orientation:UIImageOrientationUp];

Now you can use this image on your UITabBarItem.

Siteware
  • 31
  • 3
2

You can create two versions of the image and name them image.png for the 30px and image@2x.png for the 60px. Then use this:

UIImage *image = [UIImage imageNamed:@"image.png"];

The right resolution image will be loaded depending on the display on the device.

Akshay Aher
  • 2,525
  • 2
  • 18
  • 33
jamihash
  • 1,900
  • 1
  • 12
  • 15
0

what about determining whether the device is retina or not, and download different assets accordingly?

Robot Woods
  • 5,677
  • 2
  • 21
  • 30
  • 1
    Thanks for your answer, but the problem is that if I set a high resolution image (60px instead 30px) as the image for the tabBarIcon, it is drawn too big. I am missing something and dont know what.. – Aklope Apr 15 '11 at 17:28