iOS 自定义NavigationBar右侧按钮rightBarButtonItem

自定义右侧的一个按钮

 UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithTitle:@"主页" style:UIBarButtonItemStyleBordered target:self action:@selector(clickEvent)];

 self.navigationItem.rightBarButtonItem = myButton;

自定义右侧多个按钮

 //两个按钮的父类view

 UIView *rightButtonView = [[UIView alloc] initWithFrame:CGRectMake(, , , )];

 //历史浏览按钮

 UIButton *historyBtn = [[UIButton alloc] initWithFrame:CGRectMake(, , , )];

 [rightButtonView addSubview:historyBtn];

 [historyBtn setImage:[UIImage imageNamed:@"button_history"] forState:UIControlStateNormal];

 [historyBtn addTarget:self action:@selector(historyBtnEvent) forControlEvents:UIControlEventTouchUpInside];

 #pragma mark >>>>>主页搜索按钮

 //主页搜索按钮

 UIButton *mainAndSearchBtn = [[UIButton alloc] initWithFrame:CGRectMake(, , , )];

 [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;

转自:https://www.jianshu.com/p/901203a8a90e

上一篇:Android TV 遥控器适配


下一篇:iOS 自定义NavigationBar右侧按钮rightBarButtonItem--button