iOS开发中经常要在在导航栏添加回退、或者搜索、或者保存按钮。下面就是自定义按钮的方法。
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;