35

我有一个自定义UIBarButtonItem的图像在 iOS 6.1 中运行良好。但是 iOS 7 有一个tintColor,它会在我的图像上覆盖这种颜色。如果我将按钮设置tintColor[UIColor clearColor]不会一起显示。

如何让我的后退按钮像在 iOS 6 中一样显示在 iOS 7 中?请帮忙?

iOS 6.1

IOS 7

4

6 回答 6

43

您应该使用 UINavigationBar 上的外观来全局设置自定义后退按钮。

[UINavigationBar appearance].backIndicatorImage = customBackButton;
[UINavigationBar appearance].backIndicatorTransitionMaskImage = customBackButton;
于 2015-04-29T08:02:17.473 回答
23

尝试UIBarButtonItem在 ios7 中这样设置:-

UIImage *temp = [[UIImage imageNamed:@"theImage"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];    
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithImage:temp style:UIBarButtonItemStyleBordered target:self action:@selector(action)];

这是苹果开发中心讨论论坛中的原始帖子

为了同时支持 iOS7 和更低版本,您可以检查system-version并设置如下代码:-

UIImage *temp=nil;

if([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0)
{ 
    temp = [UIImage imageNamed:@"btn-back.png"]; 
}
else
{ 
    temp = [[UIImage imageNamed:@"btn-back.png"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];
 }
于 2013-09-20T09:15:05.487 回答
20

对于不想与现有目标动作等混淆的人来说,以下似乎更有意义。只需复制和粘贴即可。这也迫使 iOS 使用您的图像及其所有风格 - 而不是简单地使用图像的模板/印象。

- (void)setCustomNavigationBackButton
{
    UIImage *backBtn = [UIImage imageNamed:@"arrow"];
    backBtn = [backBtn imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.backBarButtonItem.title=@"";
    self.navigationController.navigationBar.backIndicatorImage = backBtn;
    self.navigationController.navigationBar.backIndicatorTransitionMaskImage = backBtn;
}

arrow是您的图像的名称。

于 2014-08-07T21:34:33.310 回答
8

快速版本:

var backBtn = UIImage(named: "return_menu")
backBtn = backBtn?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)

self.navigationController!.navigationBar.backIndicatorImage = backBtn;
self.navigationController!.navigationBar.backIndicatorTransitionMaskImage = backBtn;
于 2015-07-26T07:55:50.440 回答
6

试试这种方式:

self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:nil action:nil];
self.navigationController.navigationBar.backIndicatorImage = [UIImage imageNamed:@"yourImageName.png"];
self.navigationController.navigationBar.backIndicatorTransitionMaskImage = [UIImage imageNamed:@"yourImageName.png"];

这将创建一个全局色调颜色的图像蒙版,为您提供您自己的自定义图标。不适用于彩色图像。

于 2014-01-31T10:58:58.117 回答
0

// 将图像添加到按钮

UIButton *refreshButton = [UIButton buttonWithType:UIButtonTypeCustom];
[refreshButton setFrame:CGRectMake(0,0,30,30)];
refreshButton.userInteractionEnabled = YES;
[refreshButton setImage:[UIImage imageNamed:@"yourimage.jpg"] forState:UIControlStateNormal];

// ASSIGNING THE BUTTON WITH IMAGE TO BACK BAR BUTTON

UIBarButtonItem *refreshBarButton = [[[UIBarButtonItem alloc] initWithCustomView:refreshButton] autorelease];
self.navigationItem.leftBarButtonItem = refreshBarButton;
于 2013-09-20T10:07:49.970 回答