You should use applicationFrame
instead of bounds
. bounds
will return you size including status bar while applicationFrame
will return you frame of content for your app.
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
In iOS7 status bar can be translucent. This means that applicationFrame
and bounds
will return same frame because content can be drawn bellow status bar. To fix this you can offset you window bellow status bar (20px
)
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
_window.clipsToBounds = YES;
_window.frame = CGRectMake(0, 20, _window.frame.size.width, _window.frame.size.height - 20);
_window.bounds = CGRectMake(0, 20, _window.frame.size.width, _window.frame.size.height);
To make this work on all versions, add system version condition, like this:
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
_window.clipsToBounds = YES;
_window.frame = CGRectMake(0, 20, _window.frame.size.width, _window.frame.size.height - 20);
_window.bounds = CGRectMake(0, 20, _window.frame.size.width, _window.frame.size.height);
}
It's still better to avoid modifying window frame, use applicationFrame
and offset your content view for 20px
from the top on iOS7 with translucent status bar.