0

I set background of view as below:

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:
@"backgr.png"]];

It is working fine when i run it in iphone 4(Retina 3.5-inch). But when i run it in iphone 5(Retina 4-inch) image didn't set or displayed correctly.Image looks like 4 times zoom in/ blows up.

EDIT:

 I have two different images for iphone 4(640x960) and 5(640x1136).

 What is the problem here? Is it scaling problem or another problem?
 Please guide me on this.
Ponting
  • 2,248
  • 8
  • 33
  • 61

3 Answers3

1

the resolution for both the displays are different so you need to put condition and accordingly set the new image with higher resolution for iPhone 5 (4 inch retina) display.

and that condition you can put like

if ((int)[[UIScreen mainScreen] bounds].size.height == 568)
{
    // This is iPhone 5 screen
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"backgr_iPhone5.png"]];
} else {
    // This is iPhone 4 screen
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"backgr.png"]];
}
D-eptdeveloper
  • 2,430
  • 1
  • 16
  • 30
1

Here is something that can be handy :

#define IS_PHONEPOD5() ([UIScreen mainScreen].bounds.size.height == 568.0f && 
[UIScreen mainScreen].scale == 2.f &&
 UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

and

- (void)viewDidLoad
{
    [super viewDidLoad];

        if(IS_PHONEPOD5())
        {
                self.imageView.image = [UIImage imageNamed:@"image-568h@2x"];
        }
        else
        {
                self.imageView.image = [UIImage imageNamed:@"image"];
        }
}
LudoZik
  • 917
  • 1
  • 8
  • 20
0

You need to use two different image for iPhone 4 and iPhone 5.Because both device have different resolution. You need to check like this.

if ([UIScreen mainScreen].bounds.size.height == 568)
    {
        // ------- iPhone 5
    }
    else
    {
        // ---------- iPhone 4
    }
Dharmbir Singh
  • 17,485
  • 5
  • 50
  • 66