Reputation: 6392
Below is my code from app delegate in didFinishLaunchingWithOptions
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
CGRect windowFrame = self.window.frame;
UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, windowFrame.size.height-100, windowFrame.size.height, windowFrame.size.height)];
bottomView.backgroundColor = [UIColor redColor];
[self.window addSubview:bottomView];
// self.viewController.view.frame = CGRectMake(0, 0, windowFrame.size.width, windowFrame.size.height-100);
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
My ViewController is FreeForm and its height is just around 245. As you can see i am trying to put a bottom view that is 100 points height.
I am just trying to learn this.
But the view always filling the entire screen. If i comment out setting view controller as windows rootviewcontroller i can see my bottomview there on the screen.
What i am doing wrong? Please advice.
Thanks.
Upvotes: 5
Views: 2786
Reputation: 6392
Instead of
self.window.rootViewController = self.viewController;
when i code
[self.window addSubview:self.viewController.view];
gave me the expected result and it governs the freeform size.
It appears when set as rootviewcontroller it fills the entire available screen regardless of the freeform size set on the XIB.
Upvotes: 3
Reputation: 104092
I'm not sure why you're trying to do this, but the freeform setting in IB (at least for xib files) seems to be for layout purposes only. It doesn't actually affect the size you get when the view loads. If you want it to be shorter, then set its frame in the viewDidAppear: method in ViewController, not in the app delegate -- the view hasn't been loaded there yet, so it's too early to set the frame.
Upvotes: 0
Reputation: 47099
write only one sentance
[self.window bringSubviewToFront: bottomView];
OR
Add bottomView to window as ,
[[[[UIApplication sharedApplication] delegate] window] addSubview:bottomView];
Upvotes: 2