首页 > 代码库 > 美团HD(2)-设置导航栏内容
美团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
最终效果:
美团HD(2)-设置导航栏内容
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。