zoukankan      html  css  js  c++  java
  • 统一设置导航栏与状态栏代码

    统一设置导航栏与状态栏代码:

    #import "AppDelegate.h"
    #import "SZMMainTabBarController.h"
    @interface AppDelegate ()
    
    @end
    
    @implementation AppDelegate
    
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
        //创建window
        self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
        
        //创建要控制器
        SZMMainTabBarController *mainVc = [[SZMMainTabBarController alloc]init];
        
        //将mainVc设置为window的根控制器
        self.window.rootViewController = mainVc;
        
        //统一设置导航栏
        [self setNavBar];
        
        //统一设置状态栏
        [self setStatusBar:application];
        //设置self.window 为主控制器并显示
        [self.window makeKeyAndVisible];
        
        return YES;
    }
    
    //统一设置导航栏
    - (void)setNavBar{
        //用appearance方法获得全局代理对象,然后对全局代理对象进行设置便设置了所有的导航栏
        UINavigationBar *NavBar = [UINavigationBar appearance];
        [NavBar setBackgroundImage:[UIImage imageNamed:@"NavBar64"] forBarMetrics:UIBarMetricsDefault];
        NSDictionary *arrtu = @{NSForegroundColorAttributeName:[UIColor whiteColor]};
        //修改导航栏中标题文字的颜色
        [NavBar setTitleTextAttributes:arrtu];
        //修改导航栏中返回按钮的颜色
        [NavBar setTintColor:[UIColor whiteColor]];
        
        
    }
    
    //统一设置状态栏
    - (void)setStatusBar:(UIApplication *)application
    {
        //设置状态栏为白色
        application.statusBarStyle = UIStatusBarStyleLightContent;
        //设置状态栏在程序启动后显示(注意要在info.plist文件中添加View controller-based status bar appearance这一项为NO 并且 将程序的hide status bar 选项勾选(此选项在程序general中勾选))
        application.statusBarHidden = NO;
    }
    
    - (void)applicationWillResignActive:(UIApplication *)application {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    }
    
    - (void)applicationDidEnterBackground:(UIApplication *)application {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }
    
    - (void)applicationWillEnterForeground:(UIApplication *)application {
        // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    }
    
    - (void)applicationDidBecomeActive:(UIApplication *)application {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }
    
    - (void)applicationWillTerminate:(UIApplication *)application {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }
    
    @end
  • 相关阅读:
    第六天20160802
    第五天20160801
    关于表单元素input的美化
    关于Oracle默认用户名system密码不正确登录不上解决方案
    ORCALE安装教程
    [INS-32021]此卷上用于所选Oracle主目录的磁盘空间不足
    Linux下利用nc命令传输文件
    golang与 postgresql简单的增删改查
    Golang 调用 C/C++,例子式教程
    c# EF中equal的用法注意
  • 原文地址:https://www.cnblogs.com/ZMiOS/p/5023034.html
Copyright © 2011-2022 走看看