ios-Set the status bar style for some pages

Source: Internet
Author: User
Tags uikit
Global page status bar style white light

Before the project is the global white status bar style, you can add the following options in the Plist file, and then write a code in the base controller to achieve the status of the global status bar white.

[[UIApplication sharedapplication] setstatusbarstyle:uistatusbarstylelightcontent];  
partial page status bar style white light

After IOS 7, Uiviewcontroller has a new approach:-Preferredstatusbarstyle, which allows the user to specify the status bar style.

But I tried it, but it didn't work. Later we know why: This method works only if the Viewcontroller is not included in the Uinavigationcontroller. In most cases, Viewcontroller will not be used alone and will generally be nested in Uinavigationcontroller.

So you can write a uinavigationcontroller extension that overrides its default implementation and returns the top Viewcontroller Preferredstatusbarstyle.

Oc

Uinavigationcontroller+statusbar.h
#import <UIKit/UIKit.h>

@interface Uinavigationcontroller ( StatusBar)
-(Uistatusbarstyle) Preferredstatusbarstyle;
@end

//uinavigationcontroller+statusbar.m
#import "Uinavigationcontroller+statusbar.h"

@ Implementation Uinavigationcontroller (StatusBar)
-(Uistatusbarstyle) Preferredstatusbarstyle {return
    [ Self Topviewcontroller] preferredstatusbarstyle];
}
@end

Swift

Extension Uinavigationcontroller {
    override public func Preferredstatusbarstyle ()-> Uistatusbarstyle {
        Return Self.topViewController.preferredStatusBarStyle ()
    }

Then where do I need to introduce the Uinavigationcontroller+statusbar.h header file, this time the Preferredstatusbarstyle works. If you use Swift, add the extension and you are done.

Reference address

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.