How to hide the status bar programmatically in iOS 7?

后端 未结 12 1741
眼角桃花
眼角桃花 2020-12-05 17:00

In ios7, how can I hide the statusbar programmatically? I am using XCode 4.6.1 (ios6.1) and I want to implement this in XCode itself.

相关标签:
12条回答
  • 2020-12-05 17:50
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)])
        {
            [self prefersStatusBarHidden];
            [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
        }
        else
        {
            // iOS 6
            [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
        }
    }
    
    // Add this method
    - (BOOL)prefersStatusBarHidden {
        return YES;
    }
    
    0 讨论(0)
  • 2020-12-05 17:52

    To hide for a specific ViewController (and then turn back on) when View controller-based status bar appearance set to NO:

    -(void)viewDidAppear:(BOOL)animated {
        [super viewDidAppear:animated];
        [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
    }
    
    -(void)viewWillDisappear:(BOOL)animated {
        [super viewWillDisappear:animated];
        [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
    }
    
    0 讨论(0)
  • 2020-12-05 17:53

    on swift 4:

        UIApplication.shared.isStatusBarHidden = ..true/false
    
    0 讨论(0)
  • 2020-12-05 18:02

    in iOS7 you should implement in your viewController

    - (BOOL)prefersStatusBarHidden {
        return YES;
    }
    
    0 讨论(0)
  • 2020-12-05 18:02

    If anyone wanted the most updated way to do it (Swift 2.1 and latest Xcode 7.2)

    1. Set "View controller based status bar appearance to NO in your info.plist"

    2. UIApplication.sharedApplication().statusBarHidden = true // put inside app delegate somewhere (applicationWill or DidFinishLaunchingWithOptions:

    0 讨论(0)
  • 2020-12-05 18:06

    you can hide status bar to set the key value "View controller-based status bar appearance" NO in plist. This is easiest way.

    or You can hide in code by using property statusBarHidden of UIApplication class.

    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    

    Swift 3.0

    Hide status bar for any particular view controller

    override var prefersStatusBarHidden: Bool {
        get {
            return true
        }
    }
    

    Hide Status bas across the application

    UIApplication.shared.isStatusBarHidden = true

    and set the key value "View controller-based status bar appearance" NO in info plist of project.

    0 讨论(0)
提交回复
热议问题