I can’t figure out why that view takes the entire screen.
In AppDelegate file
…
self.viewController = [[[ViewController alloc]init]autorelease];
[self.window setRootViewController:self.viewController];
self.window.backgroundColor = [UIColor whiteColor];
..
In ViewController.m
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(30, 30, 30, 30)];
[view setBackgroundColor:[UIColor greenColor]];
self.view = view;
When I run the app the screen is entirely green instead of having just a square in green.
What is wrong here ?
The erroneous line is here:
When you set a view of a
UIViewControllerthat is the root controller, it is guaranteed to fill the screen. Instead, add it as a subview:And you should be fine.