导航栏使用UIButton自定义返回按钮的图片

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了导航栏使用UIButton自定义返回按钮的图片相关的知识,希望对你有一定的参考价值。

- (void)viewDidLoad {

UIButton *backItem = [UIButton buttonWithType:UIButtonTypeCustom];

    UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithCustomView:backItem];

    backItem.frame = CGRectMake(18, 5, 20, 20);

    [backItem setImage:[UIImage imageNamed:@"返回 (6)"] forState:UIControlStateNormal];

    [backItem addTarget:self action:@selector(backSection1) forControlEvents:UIControlEventTouchUpInside];

    self.navigationItem.leftBarButtonItem = back;

}

-(void)backSection1{

if (viewcontrollers.count>1) {

  if ([viewcontrollers objectAtIndex:viewcontrollers.count-1]==self) {
 
 
  //push方式 [self.navigationController popViewControllerAnimated:YES];
 
 
  }
} else{
 
 
//present方式 [self.navigationController dismissViewControllerAnimated:YES completion:nil];
 
 
}



以上是关于导航栏使用UIButton自定义返回按钮的图片的主要内容,如果未能解决你的问题,请参考以下文章

iOS中自定义导航栏左边返回按钮和按钮不能靠左的问题

自定义后退按钮图像在导航栏上不起作用

iOS 导航栏-返回按钮-自定义

Swift - 重写导航栏返回按钮

小程序自定义单页面全局导航栏

IOS 自定义导航栏标题和返回按钮标题