Skip to content

Instantly share code, notes, and snippets.

@Blackjacx
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Blackjacx/9fc15cc1f12f7de830fb to your computer and use it in GitHub Desktop.
Save Blackjacx/9fc15cc1f12f7de830fb to your computer and use it in GitHub Desktop.
Different Ways of statusbarHeight
CGFloat statusBarHeight = CGRectGetMaxY([self.view.window convertRect:UIApplication.sharedApplication.statusBarFrame toView:self.view]);
#define kStatusBarHeight [self.window convertRect:UIApplication.sharedApplication.statusBarFrame toView:self].size.height
- (CGFloat)AT_statusBarHeight
{
CGFloat statusBarHeight = 0.f;
if (kIS_IOS7_RUNTIMECHECK && !self.statusBarHidden)
{
statusBarHeight = CGRectGetWidth(self.statusBarFrame);
}
else if (kIS_IOS8_OR_HIGHER_RUNTIMECHECK)
{
statusBarHeight = CGRectGetHeight(self.statusBarFrame);
}
return statusBarHeight;
}
- (CGFloat)statusBarHeight
{
// Get the status bar frame
CGRect statusBarFrame = UIApplication.sharedApplication.statusBarFrame;
CGFloat statusBarHeight;
// On iOS 8 and above checks for the interface orientation aren't required anymore which leads to the point that the height of the statusbar is always the height value of the statusbar frame
if (kIS_IOS8_OR_HIGHER_RUNTIMECHECK)
{
statusBarHeight = statusBarFrame.origin.y + CGRectGetHeight(statusBarFrame);
}
else
{
// If the legal view controller is in landscape mode
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
{
// Calculate the height of the status bar with origin.y and width
// of the status bars frame
statusBarHeight = statusBarFrame.origin.y + CGRectGetWidth(statusBarFrame);
}
// else (legal view controller is in portrait mode)
else
{
// Calculate the height of the status bar with origin.x and height
// of the status bars frame
statusBarHeight = statusBarFrame.origin.x + CGRectGetHeight(statusBarFrame);
}
}
return statusBarHeight;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment