gpt4 book ai didi

ios - 无法自定义pushViewController的后退按钮

转载 作者:行者123 更新时间:2023-12-01 19:14:18 25 4
gpt4 key购买 nike

我有一个ViewController可以通过以下方式打开另一个ViewController

[self.navigationController pushViewController:detailViewController animated:YES];

现在,新的VC在navBar中有一个后退按钮,但是我无法为它提供与第一个ViewController中的navBar按钮相同的背景图像。我尝试过:
UIImage *buttonImage = [UIImage imageNamed: @"Button.png"];
[self.navigationItem.backBarButtonItem setBackButtonBackgroundImage:buttonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[self.navigationItem.backBarButtonItem setTitle:@"doesnt work either"];

但这是行不通的。我究竟做错了什么?谢谢!

最佳答案

试试下面的代码片段,对我来说很好:

UIBarButtonItem *barBtnItem = [[UIBarButtonItem alloc]initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(pop)];

self.navigationItem.backBarButtonItem = barBtnItem;

或者,您也可以这样做:
   UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 26, 26)];
[backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
[backButton setShowsTouchWhenHighlighted:TRUE];
[backButton addTarget:self action:@selector(popViewControllerWithAnimation) forControlEvents:UIControlEventTouchDown];
UIBarButtonItem *barBackItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.hidesBackButton = TRUE;
self.navigationItem.leftBarButtonItem = barBackItem;

享受编码:)

关于ios - 无法自定义pushViewController的后退按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14315901/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com