Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Colorwithpattern - using a custom iPhone5 image

For my app's loading screen and splash screen, I used up with two different methods to display my iPhone 3, iPhone 4 and iPhone 5 images appropriately.

For the loading screen, simply adding -568h@2x to your image is enough to support iPhone5.

For the splashscreen, I used a series of (if height == ) cases to check the height of the UIScreen's bounds and sourced the appropriate image to the image view. It was apparent to me here that the -568h isn't universally recognized as an iPhone 5 image. It is only applicable to the loading screen.

Now, in my AppDelegate, I'm setting a the background image. All my subviews have a transparent background, so they are supposed to show through to the background image. However, I am having the most trouble setting up the background image here.

Simply passing in the "Background.png" Adding the -568h@2x to the end of the filename does not work. It will do the non-retina and the 3.5'' retina display, but will not pick up for the 4'' display.

ie:

self.window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Background.png"]];

If I use the above snippet of code, the iPhone4 picture is used instead of the iPhone5 picture and this is not what I want.

I moved onto trying to do the same thing as I did with the splashscreen. I had a bunch of if cases:

CGFloat height = [UIScreen mainScreen].currentMode.size.height;

if ( height == 1136 )
{
     //Choose image here
}
else if (height == 960)
{
     //Choose image here
}
else if (height == 480)
{
     //Choose image here
}
self.window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:chosenImage]];

But the colorWithPatternImage function thinks that the chosenImage goes by 1 point = 1 pixel. So I end up with a non-retina picture attempting to fit onto the iPhone 5 screen. What exaclty does it look like? Looks like only the top left quadrant of the image I wanted is displayed over the entire iPhone 5 screen. It looks like no retina scaling was applied.

I need the iPhone to recognize that I have a retina-friendly iPhone 5 picture to be used as the background. How do I do this?

like image 437
Mark S Avatar asked Oct 11 '12 20:10

Mark S


1 Answers

I found this code here, perhaps it helps you:

UIImage *tmpImage = [UIImage imageNamed:@"[email protected]"];
UIImage *backgroundImage = [UIImage imageWithCGImage:[tmpImage CGImage]
                                               scale:2.0
                                         orientation:UIImageOrientationUp];
self.window.backgroundColor = [UIColor colorWithPatternImage:backgroundImage];
like image 187
Martin R Avatar answered Oct 28 '22 15:10

Martin R