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
Trent Burkenpas
22,388 PointsCGRect and Frame help!
So im connecting predictionLabel in VeiwController.h to VewController.m. But for some reason it is not connecting. Im not getting the same results that Amit is getting in the video. The padding around the element predictionLabel should be expanded. So the code :
- (void)viewDidLoad
{
[super viewDidLoad];
self.predictionLabel.frame = CGRectMake(50, 200, 100, 100);
}
This is where i mess up and i'm getting different results then Amit. This seem so impossible for me to explain :( hopefully you can help me out by looking at my code
for ViewConroller.h
#import <UIKit/UIKit.h>
@interface TBViewController : UIViewController
@property (strong, nonatomic) IBOutlet UILabel *predictionLabel;
- (IBAction)buttonPressed;
@end
VeiwController.m
#import "TBViewController.h"
@interface TBViewController ()
@end
@implementation TBViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.predictionLabel.frame = CGRectMake(50, 200, 100, 100);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)buttonPressed {
self.predictionLabel.text = @"YES";
}
@end
And here is the link to the video : http://teamtreehouse.com/library/build-a-simple-iphone-app-ios7-2/understanding-views-and-view-controllers/cgrect-and-frame
Any help would be awesome! If you have no idea what i'm trying to explain, i'm sorry, i'm struggling to explain the issue :p
-Thanks
3 Answers
John W
21,558 PointsviewDidLoad happens before the frame is finalized. You need to set the frame rect after that in viewDidAppear, as explained in the video starting just before the 8-minute mark.
Trent Burkenpas
22,388 Pointshmmm interesting, my results were quite different then Amit's. But i guess it really doesn't matter because he was just showing what frame can do. In the video at 11:57, you see how the text "It is decidedly so" is centered in the label box. Mine is more to the left. Im sure that is not a matter of code, but something I did in the storyboard. Is there a reason my text in more to the left and not centered? Btw thanks for all the help, I truly appreciate it.
Trent Burkenpas
22,388 PointsNVM I figured it out, thanks for the help!