Your code should work as is. I do not know what the original sizes of your image were, but I would assume that they were 64x64 px. For proper scaling, the source image must be 128x128 px.
As a test, the following code correctly displayed my photo in Retina resolution on the simulator and on my iPhone 4:
UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.seenobjects.org/images/mediumlarge/2006-08-19-native-lilac.jpg"]]]; CGRect labelFrame = CGRectMake(0, 0, 375, 249.5); UIImageView *imageView = [[UIImageView alloc] initWithFrame:labelFrame]; [imageView setImage:img]; [self.view addSubview:imageView];
Please note that UIImageView
is 375x249.5 pixels, which is half the original (pixel) size of the photo. In addition, the installation of contentScaleFactor
not required.
(Aside, I donβt see that specifying @2x
in the URL will help, in this case, since calling dataWithContentsOfURL:
will return an opaque data block, without a trace of the remaining file name. This is opaque data that was then transferred to imageWithData:
for download Images.)
source share