Last active
August 29, 2015 14:23
-
-
Save Blackjacx/9fc15cc1f12f7de830fb to your computer and use it in GitHub Desktop.
Different Ways of statusbarHeight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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