设置后退按钮自定义Outlook不起作用

时间:2015-05-29 08:21:47

标签: ios objective-c

我在设置图像方面遇到了一些困难。这有点奇怪,因为在不同的控制器中它确实有效。可能self.navigationItem无效,但是为什么我只是从不同的ViewController推送ViewController

我试过了:

// preview buttonImage shows that image is correct and exists
UIImage *buttonImage = [[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithTitle:@"TEST" style:UIBarButtonItemStylePlain target:nil action:NULL];
[buttonItem setBackButtonBackgroundImage:buttonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
self.navigationItem.backBarButtonItem = buttonItem;

不同的方法:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setTitle:@"TEST" forState:UIControlStateNormal];
[button setImage:buttonImage forState:UIControlStateNormal];
buttonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.backBarButtonItem = buttonItem;

我认为也许self.navigationItem是错误的,但似乎存在:

NSLog(@"%@, %@", self.navigationItem, self.navigationItem.backBarButtonItem);
--CONSOLE-- MyApp[56574:3827402] <UINavigationItem: 0x7b6ecd10>, <UIBarButtonItem: 0x7b6f01c0>

我甚至试图设置:

self.navigationItem.backBarButtonItem = nil;

似乎也没有用。

- 编辑 -

但是,以下代码可以工作:

[self.navigationItem setHidesBackButton:YES];

有什么建议,self.navigationItem是有效的。

1 个答案:

答案 0 :(得分:0)

显然,阿奇。我忘记了,对于我正在设置的新iOS:

UIImage *backImage = [UIImage imageNamed:@"back"];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backImage forState:UIControlStateNormal barMetrics:UIBarMetricsCompact];

因此我需要为此控制器更改它,我想使用不同的图像。