开发者

iPhone4: prevent UIImageView from scaling

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 sre开发者_JS百科enshot:

iPhone4: prevent UIImageView from scaling

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜