Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Programming a Background Image

When I run the simulator the background image only shows up in the corner of the app, and not full screen.

This is the code I have:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.crystalBall = [[TMCrystalBall alloc] init];

    UIImage *backgroundImage = [UIImage imageNamed:@"background"];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:backgroundImage];
    [self.view insertSubview:imageView atIndex:0];

}

3 Answers

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

Is this a custom image of your own or is it the one provided by us? You might also want to make sure you have included both the standard and retina versions of the image.

They were the images downloaded from the program files. I put both the regular, and the retina one in the Images.xcassets folder. It works perfectly if I do it from Main.storyboard, but not if I code it in.

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

That is strange can you share your entire project via DropBox or GitHub?

I ended up adding it via the main.storyboard, and finishing the project. I'm not sure if I can re-create the problem or not.

Hi Amit. I'm having the same problem as well. Here is a link to my entire project. Any thoughts.

BTW, this is a great class! Thanks again.

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

Just downloaded and ran your project and it worked fine for me. You could try cleaning your project. From the menu select Product -> Clean or Shift+Command+K

That worked! Thanks Amit!