zoukankan      html  css  js  c++  java
  • 美团HD(2)-设置导航栏内容

    DJHomeViewController.m

    #import "DJHomeViewController.h"
    #import "DJConstantValue.h"
    #import "DJNavTopItem.h"
    
    @implementation DJHomeViewController
    
    
    - (instancetype)init {
    
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        return [self initWithCollectionViewLayout:layout];
    }
    
    
    - (void)viewDidLoad {
    
        [super viewDidLoad];
        self.collectionView.backgroundColor = DJColor(230, 230, 230);
        
        [self setupRightNavItem];
        [self setupLeftNavItem];
    
    }
    
    
    /** 设置导航栏右侧内容 */
    - (void)setupRightNavItem {
    
        // 地图
        UIBarButtonItem *mapItem = [UIBarButtonItem itemWithTarget:self action:nil image:@"icon_map" highlighImage:@"icon_map_highlighted"];
        mapItem.customView.width = 50;
    //    mapItem.customView.backgroundColor = [UIColor redColor];
        
        // 搜索
        UIBarButtonItem *searchItem = [UIBarButtonItem itemWithTarget:self action:nil image:@"icon_search" highlighImage:@"icon_search_highlighted"];
        searchItem.customView.width = 50;
    //    searchItem.customView.backgroundColor = [UIColor greenColor];
    
        self.navigationItem.rightBarButtonItems = @[mapItem,searchItem];
    
    }
    
    
    /** 设置导航栏左侧内容 */
    - (void)setupLeftNavItem {
    
        UIImageView *logoView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_meituan_logo"]];
        UIBarButtonItem *logoItem = [[UIBarButtonItem alloc] initWithCustomView:logoView];
        
        
        DJNavTopItem *item01 = [DJNavTopItem item];
        UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithCustomView:item01];
        
        DJNavTopItem *item02 = [DJNavTopItem item];
        UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithCustomView:item02];
        
        DJNavTopItem *item03 = [DJNavTopItem item];
        UIBarButtonItem *item3 = [[UIBarButtonItem alloc] initWithCustomView:item03];
        
        self.navigationItem.leftBarButtonItems = @[logoItem,item1,item2,item3];
        
        
    }
    
    
    @end

    最终效果:

  • 相关阅读:
    CodeForces
    CodeForces
    Simple Robot Gym
    Gym
    Java课程03总结
    Java课程03总结
    判断字符串是否回文
    Java课程02总结
    有关二进制原码、反码、补码
    Java课程01总结
  • 原文地址:https://www.cnblogs.com/yongdaimi/p/6246805.html
Copyright © 2011-2022 走看看