23

I've been trying to create a full screen view. I plan on using core graphics for rendering. I am new to iPhone development so please forgive this basic question.

Here's my setup code;

- (void)loadView
{
    CGRect  rect = [[UIScreen mainScreen] bounds];
    GameView *main_view;
    main_view = [[GameView alloc] initWithFrame:rect ];
    main_view.clearsContextBeforeDrawing = NO;
    self.view = main_view;
    [main_view release];    
}

Yet when I run this I get a thin status bar at the top with the time and battery level.

I tried looking for some samples yet all the samples were opengles.

Could someone please tell me where I'm going wrong? And just how to create a full screen view.

Thanks

Adam Rosenfield
  • 390,455
  • 97
  • 512
  • 589
Rich
  • 3,722
  • 5
  • 33
  • 47

5 Answers5

55

There are two methods;

In the info.plist for your application add a boolean key UIStatusBarHidden and set it to true.

At runtime you can call setStatusBarHidden on your application to show/hide the status bar. E.g.

[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO]
prashant
  • 1,920
  • 14
  • 26
Andrew Grant
  • 58,260
  • 22
  • 130
  • 143
  • 4
    Just wanted to add a note here: be sure to add the above code *before* initializing your UIWindow. If you don't, subsequent calls to the bounds won't include the difference in height w/out the status bar. – Nirvana Tikku Jan 24 '13 at 19:57
  • [setStatusBarHidden](https://developer.apple.com/documentation/uikit/uiapplication/1622949-setstatusbarhidden) was deprecated in iOS 9.0, could you update by what it was replaced ? [prefersStatusBarHidden](https://developer.apple.com/documentation/uikit/uiviewcontroller/1621440-prefersstatusbarhidden) ? – Cfun Feb 16 '21 at 15:55
13

Since I just found the answer I was looking for here, I may as well add that the above method is now depreciated. The modern method is:

- (void)setStatusBarHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation

Thanks!

David R.
  • 268
  • 4
  • 6
4

You may also want to make your rect = [[UIScreen mainScreen] applicationFrame]

Andy Bourassa
  • 1,838
  • 2
  • 15
  • 17
2

Add below method in respective view controller

-(BOOL) prefersStatusBarHidden

It worked for me.

vaibhav
  • 117
  • 2
  • 13
0

This works and it is the easiest

UIViewControllerBasedStatusBarAppearance : NO in the .plist

Kingsley Mitchell
  • 2,412
  • 2
  • 18
  • 25