转载说明出处:(谢谢)
http://blog.csdn.net/a21064346/article/details/8135794
点击打开链接
补充一下 以前转载的一篇文章,里面是别人的东西,发现他解释得不是很清楚。
补充的文章地址为:
Navigation backBarButtonItem 设置
http://blog.csdn.net/a21064346/article/details/7744391
经过查找 官方文档,里面指出
根据苹果官方指出:backbarbuttonItem不能定义customview,所以,只能贴图或者,让leftBarButtonItem变成自定义返回按钮,自己写个方法进行[self.navigationController pop当前Item
那么这段话的意思就是说,你不能 改变backbarbutton
//定义返回按钮 UIButton *backbutton = [[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 53, 31)] autorelease]; [backbutton setTitle:NSLocalizedString(@"Ba1ck",nil) forState:UIControlStateNormal]; [backbutton.titleLabel setShadowColor:LIGHT_ORANGE_SHADDOW]; [backbutton.titleLabel setShadowOffset:CGSizeMake(0, 1)]; [backbutton.titleLabel setTextColor:[UIColor whiteColor]]; [backbutton.titleLabel setFont:[UIFont fontWithName:@"Baskerville-SemiBoldItalic" size:14]]; [backbutton.titleLabel setBackgroundColor:[UIColor clearColor]]; [backbutton.titleLabel setTextAlignment:UITextAlignmentCenter]; [backbutton addTarget:self action:@selector(NavPopControllerSelf) forControlEvents:UIControlEventTouchUpInside]; UIImage *img = [UIImage imageNamed:@"ILSBCImage.bundle/Edit_Normal.png"]; [backbutton setBackgroundImage:[img stretchableImageWithLeftCapWidth:20 topCapHeight:15] forState:UIControlStateNormal]; UIImage *imgSelected = [UIImage imageNamed:@"ILSBCImage.bundle/Edit_Selected.png"]; [backbutton setBackgroundImage:[imgSelected stretchableImageWithLeftCapWidth:20 topCapHeight:15] forState:UIControlStateHighlighted]; UIBarButtonItem *backItem = [[[UIBarButtonItem alloc] initWithCustomView:backbutton] autorelease]; self.navigationItem.leftBarButtonItem =backItem; //生成 三个导入数据的button [self newImportButton]; // self.navigationItem.backBarButtonItem = backItem;
但是下面的形式,又是可行的。
其中,style 属性 并没有去实现,barButtonItem childView并没有发生改变。只是单纯的名字换了一下。
//生效 self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"custom" style:UIBarButtonItemStylePlain target:self action:nil] autorelease]; [self.navigationItem.backBarButtonItem setImage:[UIImage imageNamed:@"icon57.png"]]; [self.navigationController.navigationBar setTintColor:[UIColor redColor]]; //不生效 [self.navigationItem.backBarButtonItem setBackButtonBackgroundImage:[UIImage imageNamed:@"icon57.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
个人建议:
还是不要去设置backBarButtonItem,利用leftBarButtonItem 代替back,因为 leftBarButtonItem 没有限制。