문제

I'm downloading a lot of images to display to the user.
Each of this images have 512x512.

In a normal resolution iPhone, everything works fine,
but in the iPhone4, they appear scaled.

If this images were being fetched from the resources,
I would simply add a @2x to the image name and everything would work,
the problem is that this images are dynamically loaded from the web.

How can I prevent this UIImageViews from scaling up on the retina display?

EDIT: Here are the sreenshot:

http://img836.imageshack.us/img836/5173/screenshot20101104at104.png

Thank you all.

도움이 되었습니까?

해결책

look at this code - I use it in a UIImage category when I want to control whether the image would be loaded with scale=2 or scale=1 ... See where NSData fetches the content of the file (in my code) and replace with your code that fetches images from the web :

if ( [[[UIDevice currentDevice] systemVersion] intValue] >= 4 && [[UIScreen mainScreen] scale] == 2.0 ) {
    if ( [[NSFileManager defaultManager] fileExistsAtPath:path] ) {
        return [self initWithCGImage:[[UIImage imageWithData:[NSData dataWithContentsOfFile:path]] CGImage] scale:2.0 orientation:UIImageOrientationUp];
    }
} else [ load here the image via imageWithContentsOfFile or whatever ]

So the trick is in the "scale" parameter of the "initWithCGImage" of the UIImage class, pass 2.0 if you are loading hi res images, or pass 1.0 if you are loading low res images - that's like the greatest control you take over the hi res image loading.

best, Marin

다른 팁

Maybe try to check if the device has retina display and if it does try scaling the image down. You can see if it has retina display with:

    if ( [[[UIDevice currentDevice] systemVersion] intValue] >= 4 && [[UIScreen mainScreen] scale] == 2.0 ) {
  //do the scaling of image(s)
}

Let me know if that does the trick.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top