1.正常设置根据
// UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
// backBtn.frame = CGRectMake(0, 6, 40, 23);
// UIImageView *backImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"back_dark_icon"]];
// backImg.frame = CGRectMake(-10, 0, 22, 22); //CGRectMake(-10, 0, 22, 22)
// [backBtn addSubview:backImg];
// [backBtn addTarget:self action:@selector(leftButtonBackPage:) forControlEvents:UIControlEventTouchUpInside];
// UIBarButtonItem *leftButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
// self.navigationItem.leftBarButtonItem = leftButtonItem;
2.leftBarButtonItems来设置
UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeSystem];
leftBtn.frame = CGRectMake(0, 0, 25,25);
[leftBtn setBackgroundImage:[UIImage imageNamed:@"back_dark_icon"] forState:UIControlStateNormal];
[leftBtn addTarget:self action:@selector(leftButtonBackPage:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem * leftBarBtn = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];;
UIBarButtonItem * spaceItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpacetarget:nil action:nil];
//将宽度设为负值
spaceItem.width = -15;
//将两个BarButtonItem都返回给NavigationItem
self.navigationItem.leftBarButtonItems = @[spaceItem,leftBarBtn];
3.向导航栏中插入一个view然后自定义
//导航栏
//控制导航栏颜色的
self.naviBkgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.navigationController.navigationBar.bounds.size.width, self.navigationController.navigationBar.bounds.size.height)];
self.naviBkgView.userInteractionEnabled = YES;
self.naviBkgView.backgroundColor = [UIColor whiteColor];
[self.navigationController.navigationBar insertSubview:self.naviBkgView atIndex:self.navigationController.navigationBar.subviews.count-1];