我有一个自定义UIBarButtonItem
,其图像在iOS 6.1中运行良好。但iOS 7有一个tintColor
,它覆盖了我的图像上的这种颜色。如果我将tintColor
设置为[UIColor clearColor]
,则按钮不会全部显示在一起。
如何在iOS 7中显示我的后退按钮,就像在iOS 6中一样?请帮帮忙?
答案 0 :(得分:40)
您应该在UINavigationBar上使用外观来全局设置自定义后退按钮。
[UINavigationBar appearance].backIndicatorImage = customBackButton;
[UINavigationBar appearance].backIndicatorTransitionMaskImage = customBackButton;
答案 1 :(得分:23)
尝试在ios7中像这样设置UIBarButtonItem
: -
UIImage *temp = [[UIImage imageNamed:@"theImage"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithImage:temp style:UIBarButtonItemStyleBordered target:self action:@selector(action)];
以下是苹果开发中心discussion Forums
中的原始帖子要同时支持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];
}
答案 2 :(得分: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
是您图片的名称。
答案 3 :(得分:7)
swift版本:
var backBtn = UIImage(named: "return_menu")
backBtn = backBtn?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
self.navigationController!.navigationBar.backIndicatorImage = backBtn;
self.navigationController!.navigationBar.backIndicatorTransitionMaskImage = backBtn;
答案 4 :(得分: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"];
这将创建全局色调颜色的图像蒙版,它将为您提供自己的自定义图标。不适用于彩色图像。
答案 5 :(得分: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;