ios,nav ,rightBarButtonItem 設(shè)置多個(gè)按鈕的方法

1 ?第一種

self.navigationController.navigationBar.topItem.leftBarButtonItem = nil;

UIToolbar*tools = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 110, 39)];

//解決出現(xiàn)的那條線

tools.clipsToBounds = YES;

//解決tools背景顏色的問(wèn)題

[tools setBackgroundImage:[UIImage new]forToolbarPosition:UIBarPositionAny? ? ? ? ? ? ? ? ? ? ? barMetrics:UIBarMetricsDefault];

[tools setShadowImage:[UIImage new]

forToolbarPosition:UIToolbarPositionAny];

//添加兩個(gè)button

NSMutableArray*buttons=[[NSMutableArray alloc]initWithCapacity:2];

button3=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:myInfo.messageTopImageNameStr] style: UIBarButtonItemStyleDone target:self action:@selector(addressBook)];

UIBarButtonItem*button2=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"more"] style: UIBarButtonItemStyleDone target:self action:@selector(selectMenu)];

button3.tintColor=[UIColor whiteColor];

button2.tintColor=[UIColor whiteColor];

[buttons addObject:button3];

[buttons addObject:button2];

[tools setItems:buttons animated:NO];

UIBarButtonItem*btn=[[UIBarButtonItem? ? alloc]initWithCustomView:tools];

self.navigationController.navigationBar.topItem.rightBarButtonItem = btn;


2 第二種


//兩個(gè)按鈕的父類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];

#pragma mark >>>>>主頁(yè)搜索按鈕

//主頁(yè)搜索按鈕

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

//把右側(cè)的兩個(gè)按鈕添加到rightBarButtonItem

UIBarButtonItem *rightCunstomButtonView = [[UIBarButtonItem alloc] initWithCustomView:rightButtonView];

self.navigationItem.rightBarButtonItem = rightCunstomButtonView;

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容