I am downloading images from a webserver for display in a table view in my iOS application using the following code:
NSURL *url = [NSURL URLWithString:[imageArray objectAtIndex:indexPath.row]];
UIImage *myImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
cell.imageView.image = myImage;
The image view is a 60×60 placeholder and 120×120 for the retina display. I am going to assume the user has an iPhone 4. However, if I size the image to 120×120 it does not correct the issue, it just becomes too big for the the imageview. If I size the image to 60×60, on the webserver that is, then the image fits fine but its a little fuzzy. Anyone know how to fix this issue?
Thanks!
Let’s first agree that your
UIImageViewis 60×60 points, meaning 60×60 pixels for a standard display and 120×120 pixels for a retina display.For a
UIImageViewat 60×60 points, the image should be 60×60 pixels at scale 1.0 for a standard display and 120×120 pixels at scale 2.0 for a retina display. This means that yourUIImageshould always have asizeof 60×60 points, but should have a differentscaledepending on the display resolution.When getting the image data from your server, you should first check the scale of the device’s screen and then request the appropriate image size (in pixels), like so:
Then you should put the image data in a
UIImageof size60x60points, at the appropriatescale:Hope this helps.