0

知道为什么自定义导航栏后退按钮图像未使用此代码显示吗?

而不是显示 uiimage 它仅以文本形式显示“< Back”默认 iOS 按钮

    [self.navigationController setNavigationBarHidden:NO animated:NO];

self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"freccia.png"] landscapeImagePhone:nil style:UIBarButtonItemStylePlain target:nil action:@selector(backBtnPress)];

可能是这个参数吗?UIBarButtonItemStylePlain

谢谢

4

3 回答 3

2

使用此代码:

UIImage *imageBack = [UIImage imageNamed:@"yourImage.png"];
UIButton *btnBack = [UIButton buttonWithType:UIButtonTypeCustom];
btnBack.bounds = CGRectMake(0, 0, imageBack.size.width, imageBack.size.height);
[btnBack setBackgroundImage:imageBack forState:UIControlStateNormal];
[btnBack addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButtonBack = [[UIBarButtonItem alloc] initWithCustomView:btnBack];

self.navigationItem.hidesBackButton = YES;
self.navigationItem.leftBarButtonItem = barButtonBack;

-(void)back {
[self.navigationController popViewControllerAnimated:YES];

}
于 2013-10-28T16:36:18.357 回答
1

您通常在父视图控制器中设置后退按钮。但是,它可能更容易使用leftBarButtonItem而不是backBarButtonItem.

于 2013-10-28T16:29:56.653 回答
0

你可以通过两种方式解决这个问题 1. 使用 leftBarButtonItem 而不是 backBarButtonItem 2. 试试下面的代码

  self.navigationItem.backBarButtonItem =[[UIBarButtonItem alloc] initWithTitle:@" " style:UIBarButtonItemStylePlain target:nil action:nil];
于 2013-10-28T16:35:40.293 回答