zoukankan      html  css  js  c++  java
  • UITextAttributeTextColor 的替换方法+自定义导航控制器的价值

    UITextAttributeTextColor 的替换方法  

         UITextAttributeTextColor 已经在iOS7.0以后被推荐使用了,UITextAttributeTextColor = deprecated in iOS 7.0,改为推荐使用UITextAttributeTextColor类来代替,具体替换方法以及相关示例代码如下:

      - 使用UITextAttributeTextColor的方法源代码如下所示:

        // 3.设置导航栏主题
        UINavigationBar *navBar = [UINavigationBar appearance];
        // 设置背景图片
        [navBar setBackgroundImage:[UIImage imageNamed:@"NavBar64"] forBarMetrics:UIBarMetricsDefault];
        // 设置标题文字颜色和字体大小
        NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
        attrs[UITextAttributeTextColor] = [UIColor whiteColor];
        attrs[UITextAttributeFont] = [UIFont systemFontOfSize:16];
        [navBar setTitleTextAttributes:attrs];
    

      - 使用UITextAttributeTextColor类代替上述代码如下:

    1. 更新后的第一种方法:

        // 设置标题文字颜色和字体大小
            NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
            attrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
            attrs[NSFontAttributeName] = [UIFont systemFontOfSize:16];
            [navBar setTitleTextAttributes:attrs];
    

    或者:

    2. 更新后的第二种方法:

        // 3.设置导航栏主题
        UINavigationBar *navBar = [UINavigationBar appearance];
        // 设置背景图片
        [navBar setBackgroundImage:[UIImage imageNamed:@"NavBar64"] forBarMetrics:UIBarMetricsDefault];
        // 设置标题文字颜色和字体大小
        [[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, [UIFont systemFontOfSize:16], NSFontAttributeName,nil]];
    

        但是在用最后一种方法实现时,自定义导航控制器以后,运行后控制器中的view都不见了。因此还是推荐使用更新后的第一种方法。

    -》但是当我为了简便起见:不用每个导航控制器的子控制器都需要逐个勾选  hide Bottom on Push。

      - 即自定义导航控制器,重写show方法,并且让stroyboard里面的相应导航控制器都定义为自定义的导航控制器,这样就可以减少很多麻烦。

    		- 重写push方法就可以拦截所有压入栈中的子控制器,统一做一些处理
    - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;
    
    		- 重写pop方法就可以拦截所有子控制器的出栈
    - (UIViewController *)popViewControllerAnimated:(BOOL)animated;
    
    /**
     *  重写这个方法,能拦截所有的push操作
     *
     */
    - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
    {
        viewController.hidesBottomBarWhenPushed = YES;
        [super pushViewController:viewController animated:animated];
    

    或者也可以重写相应的pop方法;

    - (UIViewController *)popViewControllerAnimated:(BOOL)animated
    {
        return [super popViewControllerAnimated:NO];
    }
    

    敬请指正。

  • 相关阅读:
    关于JDK中的设计模式
    关于Java中的构造方法和set方法()给属性赋值
    关于Object[]数组强转成Integer[]类型的数组.
    [ImportNew]Java中的Timer类和TimerTask类
    关于Linux最基本总结
    关于数组
    关于Linux系统和Windows系统中文件夹的命名规范
    关于数组集合之间的转换
    关于Java获取系统信息
    关于Windows常用命令
  • 原文地址:https://www.cnblogs.com/wangmaster/p/5111436.html
Copyright © 2011-2022 走看看