zoukankan      html  css  js  c++  java
  • UI基础

    如果导航控制器的BarButtonItem属性是一致的,可以重写initialize方法用来设置主题

    //再ViewDidload执行前只执行一次
    +(void)initialize
    {
        //创建的UIBarButtonItem的属性会从这里获取
        UIBarButtonItem *appearance = [UIBarButtonItem appearance];
        //普通情况下
        NSMutableDictionary *nor = [NSMutableDictionary dictionary];
        nor[NSForegroundColorAttributeName] = [UIColor orangeColor];
        nor[NSFontAttributeName] = [UIFont systemFontOfSize:15];
        [appearance setTitleTextAttributes:nor forState:UIControlStateNormal];
        //高亮情况下
        NSMutableDictionary *high = [NSMutableDictionary dictionaryWithDictionary:nor];
        high[NSForegroundColorAttributeName] = [UIColor greenColor];
        [appearance setTitleTextAttributes:high forState:UIControlStateHighlighted];
        //不可以点击情况下
        NSMutableDictionary *disable = [NSMutableDictionary dictionaryWithDictionary:nor];
        disable[NSForegroundColorAttributeName] = [UIColor grayColor];
        [appearance setTitleTextAttributes:disable forState:UIControlStateDisabled];
        /**设置背景**/
        // 技巧: 为了让某个按钮的背景消失, 可以设置一张完全透明的背景图片
    //    [appearance setBackgroundImage:[UIImage imageNamed:@"navigationbar_button_background"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    }
    

    也可以一次性设置leftBarButtonItem和rightBarButtonItem

    重写

    - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;

    -(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
    {
        /*这里传进来的是navController,
         self.viewControllers.count代表nav栈里控制器的数量,如果大于0,那就不是栈低控制器
         也就不是最开始看到的四个
         */
        if(self.viewControllers.count > 0 ){
            viewController.hidesBottomBarWhenPushed = YES;
            viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem initWithImage:@"navigationbar_back" HighImage:@"navigationbar_back_highlighted" action:@selector(back) target:self];
            viewController.navigationItem.rightBarButtonItem = [UIBarButtonItem initWithImage:@"navigationbar_more" HighImage:@"navigationbar_more_highlighted" action:@selector(more) target:self];
        }
        [super pushViewController:viewController animated:YES];
    }
    

      

  • 相关阅读:
    笔记(二) C#sql语句
    [叩响C#之门]写给初学者:多线程系列(七)——互锁(Interlocked类)
    C# Async与Await的使用
    C#线程锁使用全功略
    一个C#的加锁解锁示例
    【分析】浅谈C#中Control的Invoke与BeginInvoke在主副线程中的执行顺序和区别(SamWang)
    Control.BeginInvoke()和delegate的BeginInvoke()的区别
    crm04 action操作 和 多级过滤
    VIM和sed 替换字符串方法
    解决Centos关闭You have new mail in /var/spool/mail/root提示(转)
  • 原文地址:https://www.cnblogs.com/xj76149095/p/5350508.html
Copyright © 2011-2022 走看看