36

I want to check condition for statusbar. How can i check condition if status bar is visible or not .

please anyone guide me to do this..

Thank you all

EmptyStack
  • 50,606
  • 20
  • 144
  • 175
Prajan
  • 666
  • 1
  • 6
  • 15

4 Answers4

84

Check if status bar is hidden:

Objective C:

if ([UIApplication sharedApplication].isStatusBarHidden) {
    // do stuff here...
}

Swift:

if UIApplication.shared.isStatusBarHidden {
    // do stuff here...
}

Hide status bar:

override var prefersStatusBarHidden: Bool {
    return true
}
AamirR
  • 9,385
  • 3
  • 47
  • 59
Mobile Developer
  • 5,510
  • 1
  • 36
  • 43
  • You have an extra left bracket just before UIApplication. The correct code is if ( [UIApplication sharedApplication].statusBarHidden == YES){ //do stuff } – Harpastum Apr 13 '12 at 17:41
  • 2
    In fact [UIApplication sharedApplication].isStatusBarHidden – Johan Nov 25 '13 at 11:14
3

Swift 3

if UIApplication.shared.isStatusBarHidden {
    // Do something
}

To hide the status bar (setStatusBarHidden is deprecated in iOS 9) override in your ViewController:

override var prefersStatusBarHidden: Bool {
    return true
}
Roland Keesom
  • 7,860
  • 5
  • 42
  • 50
1

You can check the current state by using the statusBarHidden property of [UIApplication sharedApplication]

You can set the current state using – setStatusBarHidden:withAnimation:

See the docs for more awesome stuff.

HTH

Faizan S.
  • 8,547
  • 8
  • 32
  • 61
-1

U can Also check this in xib of interface builder in view attributes u can see four options for it gray/ black/ translucent/ unspecified..

IphoneBites
  • 157
  • 1
  • 7
  • 17