BDubCook
BDubCook

Reputation: 488

View not completely covering the entire screen

Once again I've searched for about 45 minutes for an answer to this question and I thought I might have found the answer but then the situation I was reading wasn't exactly like the one I'm running into.

when I add my view it seems that it's not completely covering the window I was able to get rid of the status bar at the top but there is a section of space at the bottom that the view is not covering

alt text http://img177.imageshack.us/img177/8844/picture1zjv.png

as you can see from the screenshot there is an orange bar...it's orange because I know what it actually is under there (it's the viewController's view but everything I try I can't seem to get the added view to cover the screen.

this is the only code that's run

Any help would be appreciated.

Upvotes: 0

Views: 551

Answers (4)

BDubCook
BDubCook

Reputation: 488

Ok, well I figured it out and now I feel kind of stupid...I went back to IB and realized that the height of each view was set at 460 and not 480...you guys did give me a bunch of good information and I appreciate it all. I wish I could mark them all as answers.

Thank you again, BWC

Upvotes: 0

kiyoshi
kiyoshi

Reputation: 827

I've had this problem before, I fixed it by just moving the view down 20 pixels... When you use interface builder it has that nifty little "simulate status bar" or "simulate toolbar" feature but I think its kind of finnicky.

Both Andrew and Tylers answers should work though, no shame in doing things programmatically :). If you are creating the stuff in interface builder, just do Andrew's second line though, don't need to reinitialize.

Upvotes: 1

Tyler
Tyler

Reputation: 28874

There are a few things that might be going wrong:

Your frame might be too short. In viewDidLoad: you can add a debug statement to check its height:

NSLog(@"Height is %f", self.view.frame.size.height);

It looks like you want that value to be 480, the full height of the screen.

Your origin might be too high. Similarly check your y offset:

NSLog(@"y origin is %f", self.view.frame.origin.y);

It looks like you want that value to be 0.

The origin of your superview might be too high. Assuming you this view only has one superview, this code will help check the absolute coordinates of your view's origin:

CGPoint absoluteOrigin = [self.view convertPoint:self.view.frame.origin
                                          toView:self.view.superview];
NSLog(@"y origin in superview is %f", absoluteOrigin.y);

You can just tag on a few extra .superview's to find out the coordinates in terms of the prior views.

By the way, instead of just using 480 as a magic number in your code, you might want to do something like this to get the full height:

CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
CGFloat screenHeight = appFrame.size.height;

The applicationFrame property takes into account whether or not the status bar is displayed.

Upvotes: 1

Andrew Johnson
Andrew Johnson

Reputation: 13286

You should post your code, but in general, you can make a UIView fill the screen as follows:

UIView *foo = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];

And you can set the frame later:

foo.frame = CGRectMake(0,0,320,480);

To fill the screen, you should use a 320 x 480 Rectangle, at origin (0,0). That's what that CGRectMake function above creates.

Upvotes: 1

Related Questions