iOS開(kāi)發(fā)中經(jīng)常要在在導(dǎo)航欄添加回退诊笤、或者搜索系谐、或者保存按鈕。下面就是自定義按鈕的方法讨跟。
UIButton *leftbutton=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 80, 20)];
//[leftbutton setBackgroundColor:[UIColor blackColor]];
[leftbutton setTitle:@"保存" forState:UIControlStateNormal]
UIBarButtonItem *rightitem=[[UIBarButtonItem alloc]initWithCustomView:leftbutton];
self.navigationItem.rightBarButtonItem=rightitem;