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
  • 相关阅读:
    初认识AngularJS
    (imcomplete) UVa 10127 Ones
    UVa 10061 How many zero's and how many digits?
    UVa 11728 Alternate Task
    UVa 11490 Just Another Problem
    UVa 10673 Play with Floor and Ceil
    JSON对象和字符串的收发(JS客户端用typeof()进行判断非常重要)
    HTML.ActionLink 和 Url.Action 的区别
    EASYUI TREE得到当前节点数据的GETDATA方法
    jqueery easyui tree把已选中的节点数据拼成json或者数组(非常重要)
  • 原文地址:https://www.cnblogs.com/ZMiOS/p/5023034.html
Copyright © 2011-2022 走看看