iOS 自定义NavigationBar右侧按钮rightBarButtonItem--button
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS 自定义NavigationBar右侧按钮rightBarButtonItem--button相关的知识,希望对你有一定的参考价值。
//两个按钮的父类view UIView *rightButtonView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 50)]; //历史浏览按钮 UIButton *historyBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 50)]; [rightButtonView addSubview:historyBtn]; [historyBtn setImage:[UIImage imageNamed:@"button_history"] forState:UIControlStateNormal]; [historyBtn addTarget:self action:@selector(historyBtnEvent) forControlEvents:UIControlEventTouchUpInside]; //主页搜索按钮 UIButton *mainAndSearchBtn = [[UIButton alloc] initWithFrame:CGRectMake(50, 0, 50, 50)]; [rightButtonView addSubview:mainAndSearchBtn]; [mainAndSearchBtn setImage:[UIImage imageNamed:@"button_filter-"] forState:UIControlStateNormal]; [mainAndSearchBtn addTarget:self action:@selector(mainAndSearchBtnEvent) forControlEvents:UIControlEventTouchUpInside]; //把右侧的两个按钮添加到rightBarButtonItem UIBarButtonItem *rightCunstomButtonView = [[UIBarButtonItem alloc] initWithCustomView:rightButtonView]; self.navigationItem.rightBarButtonItem = rightCunstomButtonView;
以上是关于iOS 自定义NavigationBar右侧按钮rightBarButtonItem--button的主要内容,如果未能解决你的问题,请参考以下文章
iOS 7 NavigationBar 后退按钮自定义图像没有标签
自定义 NavigationBar 按钮在 iOS 7 中看起来不同