iOS OC和swift更改状态栏的颜色

来源:互联网 发布:网络电影痞子兵王 编辑:程序博客网 时间:2024/06/14 05:55

有时候我们要设置一下我们状态栏的颜色,默认为黑色,那那我们要如何处理呢

两个语言都需要设置

首先在我们plist文件中加入下面这个,View controller-based status bar appearance 

它的类型时bool类型,设置为 NO


OC 接着我们只要在Appdelegate中下面的方法中加入下面这句话

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

}

加入 : [[UIApplicationsharedApplicationsetStatusBarStyle:UIStatusBarStyleLightContentanimated:NO];

setStatusBarStyle: 为想要的类型,为枚举,我们只要设置自己想要的类型即可,UIStatusBarStyleLightContent这个是白色

typedef NS_ENUM(NSInteger, UIStatusBarStyle) {

    UIStatusBarStyleDefault                                     = 0// Dark content, for use on light backgrounds

    UIStatusBarStyleLightContent     NS_ENUM_AVAILABLE_IOS(7_0) =1// Light content, for use on dark backgrounds

    

    UIStatusBarStyleBlackTranslucent NS_ENUM_DEPRECATED_IOS(2_0,7_0, "Use UIStatusBarStyleLightContent") =1,

    UIStatusBarStyleBlackOpaque      NS_ENUM_DEPRECATED_IOS(2_0,7_0, "Use UIStatusBarStyleLightContent") =2,

__TVOS_PROHIBITED;

Swift

func application(_ application:UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey:Any]?) ->Bool {

        UIApplication.shared.setStatusBarStyle(UIStatusBarStyle.lightContent, animated: false)

        let tab =MyTabBarController();

        let nav =UINavigationController.init(rootViewController: tab)

        nav.navigationBar.isHidden =true

        self.window?.rootViewController = nav

        return true

    }


阅读全文
0 0
原创粉丝点击