2

I have a problem with displaying a background image on the iPhone 5. I have added 3 images to the project. First one is named main_background.png second one is main_background@2x.png and the third one is main_background-586h@2x.png. In the init method I assigned the image to the background like this:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"main_background"]];
    }
    return self;
}

I ran the application on my iPhone 5 and it picked the @2x image. It started repeating it on the y axis. What am I doing wrong and how to fix this?

Majster
  • 3,611
  • 5
  • 38
  • 60
  • Make sure X-stupid-code **actually** copied over the file to the device. –  Oct 20 '12 at 09:34

1 Answers1

4

You need to handle this yourself. Using the suffix -586h@2x only works for the launch image.

pre
  • 3,475
  • 2
  • 28
  • 43
  • Wow, incredible. Thank god I found this https://github.com/erica/uidevice-extension/ on GitHub. It makes the process a little easier :) – Majster Oct 20 '12 at 09:48
  • @Majster: `colorWithPatternImage:` does not "know" that a 1136x640 pixel image has Retina solution, even if it is named "xxx-568h@2x.png", so this might also be useful: http://stackoverflow.com/questions/12847541/ios-colorwithpattern-using-a-custom-iphone5-image – Martin R Oct 20 '12 at 09:59