Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIView full screen

Tags:

ios

I am creating a UIview using the following code:

UIview* baseView = [[UIview alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
//self.view = baseView;
[self.view addSubview:baseView];
[baseView setBackgroundColor:[UIColor blackColor]];
baseView.userInteractionEnabled = YES;
baseView.alpha = 0.7;

The only problem is that even if I am using the mainScreen option to set it full screen, it appears full screen except for a 5cm line at the top of the UIWindow. Is there any reason for this?

like image 661
Alessandro Avatar asked Mar 20 '13 16:03

Alessandro


1 Answers

Okay, so the reason why this happens is because [[UIScreen mainScreen] applicationFrame] will return the frame of the window minus the size of the status bar if it is visible.

To fix it a simple way would be:

 UIView* baseView = [[UIView alloc] initWithFrame:CGRectMake(0,
                                                             0,
                                                             [[UIScreen mainScreen] applicationFrame].size.width,
                                                             [[UIScreen mainScreen] applicationFrame].size.height)];
//self.view = baseView;
[self.view addSubview:baseView];
[baseView setBackgroundColor:[UIColor blackColor]];
baseView.userInteractionEnabled = YES;
baseView.alpha = 0.7;
like image 178
Petar Avatar answered Oct 06 '22 03:10

Petar