[UIApplication sharedApplication].statusBarFrame.size.height
. But since all sizes are in points, not in pixels, status bar height always equals 20.
Update. Seeing this answer being considered helpful, I should elaborate.
Status bar height is, indeed, equals 20.0f points except following cases:
- status bar has been hidden with
setStatusBarHidden:withAnimation:
method and its height equals 0.0f points;
- as @Anton here pointed out, during an incoming call outside of Phone application or during sound recording session status bar height equals 40.0f points.
There's also a case of status bar affecting the height of your view. Normally, the view's height equals screen dimension for given orientation minus status bar height. However, if you animate status bar (show or hide it) after the view was shown, status bar will change its frame, but the view will not, you'll have to manually resize the view after status bar animation (or during animation since status bar height sets to final value at the start of animation).
Update 2. There's also a case of user interface orientation. Status bar does not respect the orientation value, thus status bar height value for portrait mode is [UIApplication sharedApplication].statusBarFrame.size.height
(yes, default orientation is always portrait, no matter what your app info.plist says), for landscape - [UIApplication sharedApplication].statusBarFrame.size.width
. To determine UI's current orientation when outside of UIViewController
and self.interfaceOrientation
is not available, use [UIApplication sharedApplication].statusBarOrientation
.
Update for iOS7. Even though status bar visual style changed, it's still there, its frame still behaves the same. The only interesting find about status bar I got –?I share: your UINavigationBar
's tiled background will also be tiled to status bar, so you can achieve some interesting design effects or just color your status bar. This, too, won't affect status bar height in any way.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…