0

I have this appearing in my emulator:

enter image description here

And I am not certain why the background image does not extend all the way down the screen.

One possibility is that for some reason, as default, the emulator begins at the horizontal view, and I have to shift it left to get to the image I posted.

Maybe the fix is to have the default as portrait view? How do I set that? I am actually not sure why suddenly one day I started having horizontal instead of portrait view as default.

Thanks, Alex

EDIT:

Here is how I set the background image:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
    {
        //load iphone image
        UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"building"]];
        imgView.frame = self.view.bounds; // to set the frame to your view's size
        [self.view addSubview:imgView];
        [self.view sendSubviewToBack:imgView];
    }
    else
    {
        //load ipad image
        UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"building@2x"]];
        imgView.frame = self.view.bounds; // to set the frame to your view's size
        [self.view addSubview:imgView];
        [self.view sendSubviewToBack:imgView];
    }
}
Jakub
  • 13,712
  • 17
  • 82
  • 139
Genadinik
  • 18,153
  • 63
  • 185
  • 284

1 Answers1

2

No that's not a reason because you get status bar correctly. Do you use InterfaceBuilder or add UIImageView programmatically?

if you are usin IB how do you set the background image? If you add UIImageView programmatically what size do you set in frame? Or maybe you're using pattern to set background color?

Maybe your XIB have horizontal orientation?

Please post screenshot from XIB with Attributes Inspector or some code.

EDIT:

First, you're not using @2x correctly. This is a iPhone regular or iPhone Retina managed by Xcode image tag.

And this is why you have an error:

imgView.frame = self.view.bounds;

Bounds is different then frame. Try use:

imgView.frame = self.view.frame;

Here its why: Difference between view's frame and view's bound + iPhone

The frame is the view's location in its superview, using superview's coordinate system.

The bounds is its location and size in its own coordinate system.

This is an excellent explanation. So when you're using bounds you may have confused width and height. Try to NSLog it or po in debugger and you will see.

Community
  • 1
  • 1
Jakub
  • 13,712
  • 17
  • 82
  • 139
  • Thank you for your comment. I posted the code for how I set the background image. I am a bit confused which storyboard element I need to highlight to show the attributes for it. Could you please clarify that part. – Genadinik Dec 14 '12 at 18:08
  • I just changed it to imgView.frame = self.view.frame; but still same result :( – Genadinik Dec 14 '12 at 18:12
  • And your `building` image have landscape or portrait orientation? – Jakub Dec 14 '12 at 18:15
  • those are all portrait orientation – Genadinik Dec 14 '12 at 18:19
  • So you need to debug it. In portrait: `self.view.frame.size.height` and `imgView.frame.size.height` should be equal. Check also `imgView.image.size.height`. – Jakub Dec 14 '12 at 18:23
  • Is it possible that the problem may be that the last button is causing the image to be cut off? I had a problem with the last button where I had to manually set it to not add extra space from bottom or top of the screen. – Genadinik Dec 14 '12 at 18:25
  • I don't understand what you've done with button, but AFAIK you add it into self.view. So there shouldn't be a problem. Please check if frame is equal. You may also set ContentMode: `imgView.contentMode = UIViewContentModeScaleAspectFill;` – Jakub Dec 14 '12 at 18:28