- 以在導(dǎo)航欄右側(cè)添加按鈕為例
//添加編輯按鈕
UIButton *editBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[editBtn setTitle:@"編輯" forState:UIControlStateNormal];//設(shè)置按鈕標(biāo)題
[editBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];//設(shè)置標(biāo)題字體顏色
editBtn.titleLabel.font = [UIFont systemFontOfSize:17];//設(shè)置標(biāo)題字體大小
editBtn.frame = CGRectMake(0, 0, 50, 30);//設(shè)置按鈕frame
[editBtn addTarget:self action:@selector(edit:) forControlEvents:UIControlEventTouchUpInside];//監(jiān)聽(tīng)點(diǎn)擊事件
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:editBtn];//添加到導(dǎo)航欄
-效果如圖
添加導(dǎo)航欄按鈕.png