内容其实很简单,只是有时候忘记了;在我们设置rightBarButton/leftBarbutton有时候发现系统的并不好看,想自定义,于是就是有这种想法了:
直接上代码,如下
NSInteger width = [[UIScreen mainScreen]bounds].size.width - 20; //获取系统的width
UIView *view_title = [[UIView alloc]initWithFrame:CGRectMake(width, 10, 20, 20)]; //生成自定义UIView UIButton *btnItem = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 20, 20)]; UIImage *image = [UIImage imageNamed:@"down.png"]; [btnItem setImage:image forState:UIControlStateNormal]; [btnItem addTarget:self action:@selector(favoriteBtnItem) forControlEvents:UIControlEventTouchUpInside];
[view_title addSubview:btnItem];
//将UIView添加到UIBarBtn中
UIBarButtonItem *btn =[[UIBarButtonItem alloc]initWithCustomView:view_title];
//设置成右边按钮位置
self.navigationItem.rightBarButtonItem = btn;