我需要将图像设置为整个应用程序的后退按钮。我在我的AppDelegate.m
文件中尝试了这段代码:
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:[UIImage imageNamed:@"back-button.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
这段代码可以正常工作,但需要注意一点;我有一个带有纹理的后退按钮图像,所以当它拉伸时,它看起来很糟糕。我试过这段代码:
UIButton* backButton = [UIButton buttonWithType:101]; // left-pointing shape
UIImage *backImage = [UIImage imageNamed:@"back-button.png"];
[backButton setBackgroundImage:backImage forState:UIControlStateNormal];
UIBarButtonItem* backItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
[backButton setTitle:@"Back" forState:UIControlStateNormal];
[[UIBarButtonItem appearance] setBackBarButtonItem:backItem];
我没有收到任何错误,但是当我尝试运行该应用程序时,它失败了,原因如下:
reason: [_UIBarItemAppearance setBackBarButtonItem:]: unrecognized selector sent to instance
我知道它失败的原因是我拥有的代码。我需要知道的是我应该用什么代码替换它。任何人都可以帮忙吗?