Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to add additional subview to uiwindow apart from rootviewcontroller

Tags:

ios

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.

like image 881
Saran Avatar asked Feb 09 '13 04:02

Saran


2 Answers

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.

like image 155
Saran Avatar answered Oct 29 '22 17:10

Saran


write only one sentance

[self.window bringSubviewToFront: bottomView];

OR

Add bottomView to window as ,

[[[[UIApplication sharedApplication] delegate] window] addSubview:bottomView];
like image 34
iPatel Avatar answered Oct 29 '22 16:10

iPatel