zoukankan      html  css  js  c++  java
  • iOS Navigation自定义设置Item

    1. 自定义NavigationController:

    @interface CustomNavigationController : UINavigationController

    2. 重写Push方法, 拦截Push进来的控制器:

    - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
    {
         // 判断Push进来的控制器是否根控制器
         if (self.childViewControllers.count > 0)
         {
              // Push时隐藏TabBarBottom(应用层级结构为TabBarController -> NavigationController时)
              viewController.hidesBottomBarWhenPushed = YES;
           
              // 添加左边Item到navigationItem
              viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self image:@“leftBarButtonImage" highlightedImage:@"leftBarButtonImage_highlighted" action:@selector(clickLeftItem)];             
    
              // 添加左边Item到navigationItem
              viewController.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self image:@“rightBarButtonImage" highlightedImage:@“rightBarButtonImage_highlighted" action:@selector(clickRightItem)];             
         }
       
         [super pushViewController:viewController animated:YES];  
    }

    Item点击事件:

    - (void)clickLeftItem
    {
         // Method
         [self popViewControllerAnimated:YES];
    }
    - (void)clickLeftItem
    {
         // Method
    }

    3. 通过Category,自定义BarButtonItem创建方法:

    + (UIBarButtonItem *)itemWithTarget:(id)target image:(NSString *)imageName highlightedImage:(NSString *)highlightedImageName action:(SEL)action
    {
        // 创建按钮
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        // 设置按钮图片
        [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:highlightedImageName] forState:UIControlStateHighlighted];
        // 设置按钮尺寸
        button.size = button.currentImage.size; // 避免图片拉伸
        // 设置按钮监听事件
        [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
       
        // 返回Item
        return [[UIBarButtonItem alloc] initWithCustomView:button];
    }
  • 相关阅读:
    GIS Cesium地图数据配置
    HDFS详解
    Hadoop学习路线图
    SecureCRT工具
    Eclipse使用技巧收集
    如何确定 Hadoop map和reduce的个数--map和reduce数量之间的关系是什么?
    HBase基本概念
    Hbase Rowkey设计
    MapReduce调度与执行原理系列文章
    LVS学习笔记及总结(思维导图版)
  • 原文地址:https://www.cnblogs.com/happyplane/p/4704320.html
Copyright © 2011-2022 走看看