Full Screen UIview

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 use the mainScreen parameter to set it to full screen, it is displayed in full screen, except for the 5 cm line at the top of the UIWindow. Is there a reason for this?

+5
source share
1 answer

Good, therefore, the reason for this is that it [[UIScreen mainScreen] applicationFrame]will return the window frame minus the size of the status bar if it is visible.

To fix this, an easy way:

 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;
+15
source

All Articles