In my FirstViewController I have write this code for switch background if device is iPhone4 or iPhone5:
Filename:
bg-for5-568@2x.png
bg-for4@2x.png
bg-for4.png
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage *backgroundImage = [[UIImage alloc] init];
if([[UIScreen mainScreen]bounds].size.height == 568)
{
backgroundImage = [UIImage imageNamed:@"bg-for5-568h"];
}
else
{
backgroundImage = [UIImage imageNamed:@"bg-for4"];
}
self.view.backgroundColor = [[[UIColor alloc] initWithPatternImage:backgroundImage] autorelease];
[backgroundImage release];
}
When i lanch the app on my simulator, the background for iphone5 show double size, out of the view.
/* RESOLVED THANK YOU */
I am not sure if this is the solution for this problem as I am missing some infos, but:
At first: Strip the
.pngfrom yourimageNamed:method. Since iOS4, you shouldn’t do this anymore. The next thing is: What are the Names of your image? Note that an iPhone5 has a retina display, and your image should be namedbg-for5-568h@2x.pngbut referred in the sourcecode asbg-for5-568h.Besides that: In almost every case where your image isn’t a photograph, what you are doing is a bad idea. And even if it is a photograph, simply use the bigger image for the iPhone 4 and 4S as well. It’s not that much bigger, so the memory footprint isn’t a problem here! Have a look on
UIImageView‘scontentModeproperty. You can use this to adjust the position of the larger image. You also might want to checkUIImageViewsclipSubviewsproperty to clip the image if it isn’t fullscreen.Trust me, in my company we had a loot of hooks for stuff like ~ipad, ~iphone, ~2x and even stretchable images. And all these hooks worked fine till the date, apple announced something similar or simply a new device. So I decided to not do these kind of hooks anymore. They seem to be very helpful in the first place, but the trouble you get when there is something new on the market isn’t worth it!