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

Resizing my photo for the crystal ball app so that it fits the screen.

I've placed my code below and I know I have to put stuff into viewdiddownload but I don't know what to put there to resize the photo so that it fits the screen...

VIEW CONTROLLER M: 


//
//  ViewController.m
//  CrystalBall
//
//  Created by akash kakumani on 6/1/13.
//  Copyright (c) 2013 akash kakumani. All rights reserved.
//

#import "ViewController.h"



@interface ViewController ()

@end

@implementation ViewController
@synthesize predictionArray;
@synthesize predictionLabel;
@synthesize colorArray;
- (void)viewDidLoad
{


    [super viewDidLoad];
        UIImage *myImage = [UIImage imageNamed:@"crystal ball.jpg"];
    UIImageView *myImageView = [[UIImageView alloc] initWithImage:myImage];
    [self.view insertSubview:myImageView atIndex:0];
    myImageView.autoresizingMask = UIViewAutoresizingFlexibleHeight;

    self.predictionArray = [[NSArray alloc] initWithObjects:@"It is certain",@"It is decidedly so",@"All signs say YES",
                            @"The stars are not aligned",
                            @"My reply is no",
                            @"It is doubtful",
                            @"Better not tell you now",
                            @"Concentrate and ask again",
                            @"Unable to answer now", nil];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)buttonPressed:(UIButton *)sender {
    self.colorArray = [[NSArray alloc] initWithObjects:UIColor.cyanColor,UIColor.blueColor,UIColor.greenColor,UIColor.yellowColor,UIColor.redColor, nil];
    NSUInteger index1 = arc4random_uniform(self.colorArray.count);
    NSUInteger index = arc4random_uniform(self.predictionArray.count);
    self.predictionLabel.text = [self.predictionArray objectAtIndex:index];
    self.predictionLabel.textColor = [self.colorArray objectAtIndex:index1];
}
@end



VIEW CONTROLLER H:

//
//  ViewController.h
//  CrystalBall
//
//  Created by akash kakumani on 6/1/13.
//  Copyright (c) 2013 akash kakumani. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController :
UIViewController{
    NSArray *predictionArray;
}
- (IBAction)buttonPressed:(UIButton *)sender;
@property (strong, nonatomic) IBOutlet
    UILabel *predictionLabel;
@property (strong,nonatomic) NSArray *predictionArray;
@property (strong, nonatomic) NSArray *colorArray;

@end

1 Answer

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

Depends on the size of your image. If you want it to fit the screen then it should be sized 320 x 416 pixels. Or you can play around with the contentMode property.