Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

switch background image iphone5 - iphone4

In my FirstViewController I have write this code for switch background if device is iPhone4 or iPhone5:

Filename: [email protected]
[email protected]
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 */

like image 330
Jimmy Avatar asked Oct 19 '12 10:10

Jimmy


2 Answers

I am not sure if this is the solution for this problem as I am missing some infos, but:

At first: Strip the .png from your imageNamed: 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 named [email protected] but referred in the sourcecode as bg-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's contentMode property. You can use this to adjust the position of the larger image. You also might want to check UIImageViews clipSubviews property 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!

like image 102
Michael Ochs Avatar answered Sep 27 '22 22:09

Michael Ochs


You should append @2x suffix to all of your retina images. In your case your image should be stored as "[email protected]". Hope it will resolve the issue.

like image 42
kidsid49 Avatar answered Sep 27 '22 23:09

kidsid49