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
James Rawls
2,451 PointsiOS App background not displaying when inserting in code form rather than storyboard
//
// ViewController.h
// CrystalBall
//
// Created by James E. Rawls, Jr. on 4/7/13.
// Copyright (c) 2013 James E. Rawls, Jr. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController {
NSArray *predictionArray;
NSArray *myColorsArray;
}
@property (strong, nonatomic) IBOutlet UILabel *predictionLabel;
@property (strong, nonatomic) NSArray *predictionArray;
@property (strong, nonatomic) NSArray *myColorsArray;
- (IBAction)buttonPressed:(UIButton *)sender;
@end
----------------------------------------------------------------------------------------------------------------------
//
// ViewController.m
// CrystalBall
//
// Created by James E. Rawls, Jr. on 4/7/13.
// Copyright (c) 2013 James E. Rawls, Jr. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize predictionLabel;
@synthesize predictionArray;
@synthesize myColorsArray;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIImage *image = [UIImage imageNamed:@"background.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[self.view insertSubview:imageView aboveSubview:0];
self.predictionArray = [[NSArray alloc] initWithObjects:
@"It is certain",
@"It is decidely 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",
@"Maybe yes",
nil];
self.myColorsArray = [[NSArray alloc] initWithObjects:
[UIColor redColor],
[UIColor blueColor],
[UIColor blackColor],
[UIColor yellowColor],
[UIColor orangeColor],
[UIColor purpleColor],
[UIColor brownColor],
nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)buttonPressed:(UIButton *)sender {
NSUInteger index = arc4random_uniform(self.predictionArray.count);
NSUInteger myColor = arc4random_uniform(self.myColorsArray.count);
self.predictionLabel.text = [self.predictionArray objectAtIndex:index];
self.predictionLabel.textColor = [self.myColorsArray objectAtIndex:myColor];
}
@end
1 Answer
Amit Bijlani
Treehouse Guest TeacherIt's possible that you still have the imageView within your Storyboard. You should delete it from the Storyboard since you are adding it within your code.