Question

i want to set an image to a custom UIView. I created the Image in Photoshop with 100 by 100 pixels. Then I did:

self.customView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Image.png"]];

And it worked just fine, except that i could see the pixels on my Retina display. Don't get me wrong i saw that coming, because i set the image in Photoshop to 100x100 and the UIView to 100x100. So due to the "false" pixel definition in xcode it is displayed with the double size pixels. But how can i create a image, say an image with 200x200 and then set it to the background of the 100x100 View so it is displayed with native resolution. I tried to search for something like "scale to fit"-function for the backgroundPattern for the UIView but couldn't find anything. So my question is, how do i set an image as "Retina 2x" Image? And how do i get it into my UIView?

Thanks in advance!

Was it helpful?

Solution

This is your answer.

Basically put two images in your project. "Image.png" and "Image@2x.png". The code inside [UIImage imageNamed:@"Image.png"] will pull from the correct image based on the screen hardware.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top