控制器navigationItem.LeftBarButtonim在IOS7中更改颜色

控制器navigationItem.LeftBarButtonim在IOS7中更改颜色,ios,uinavigationbar,Ios,Uinavigationbar,我有一个图像分配给IOS7上的navigationItem.LeftBarButtonim。当我从设计师那里得到它时,它在导航栏的背景上看起来很好。但当我在IOS7中实现它时,它变得苍白,几乎消失了 这就是它的设置方式: UIBarButtonItem *button = [[barButtonItemClass alloc] initWithImage:[UIImage imageNamed:@"nav_menu_icon.png"] style:UIBarButtonItemStyleBor

我有一个图像分配给IOS7上的navigationItem.LeftBarButtonim。当我从设计师那里得到它时,它在导航栏的背景上看起来很好。但当我在IOS7中实现它时,它变得苍白,几乎消失了

这就是它的设置方式:

UIBarButtonItem *button = [[barButtonItemClass alloc] initWithImage:[UIImage imageNamed:@"nav_menu_icon.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(showLeft:)];
viewController.navigationItem.leftBarButtonItem = button;
这就是它的外观(图片来自我的设计师):

这就是它在实现时的样子(在模拟器或手机上):


解决办法是什么

您应该将导航栏的着色颜色设置为着色栏中的所有项目

一个很好的解决方案是使用iOS5中引入的
UIAppearance
协议。 在AppDelegate的
ApplicationIDFinishLaunching
方法中,输入以下代码:

[[UINavigationBar appearance] setTintColor: [UIColor whiteColor]];
注意,我目前无法尝试该代码


干杯

您应该将导航栏的着色颜色设置为着色栏中的所有项目

一个很好的解决方案是使用iOS5中引入的
UIAppearance
协议。 在AppDelegate的
ApplicationIDFinishLaunching
方法中,输入以下代码:

[[UINavigationBar appearance] setTintColor: [UIColor whiteColor]];
注意,我目前无法尝试该代码


干杯

这对我来说很好:

 UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithImage:backButtonImage style:UIBarButtonItemStyleBordered target:self action:@selector(backBtnAction)];
    customItem.imageInsets = UIEdgeInsetsMake(0.0, -10, 0, 0);// For adjusting the image
    [customItem setBackgroundVerticalPositionAdjustment:+3.0f forBarMetrics:UIBarMetricsDefault];
    [self.navigationItem setHidesBackButton:YES];// Hide the Default back button before set custom
    [self.navigationItem setLeftBarButtonItem: customItem];

希望,原因可能与色调有关,这对我来说很好:

 UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithImage:backButtonImage style:UIBarButtonItemStyleBordered target:self action:@selector(backBtnAction)];
    customItem.imageInsets = UIEdgeInsetsMake(0.0, -10, 0, 0);// For adjusting the image
    [customItem setBackgroundVerticalPositionAdjustment:+3.0f forBarMetrics:UIBarMetricsDefault];
    [self.navigationItem setHidesBackButton:YES];// Hide the Default back button before set custom
    [self.navigationItem setLeftBarButtonItem: customItem];

希望,原因可能是带有
色彩的

试试这个,可能会对你们有所帮助

//解决您的框架问题

UIImage * bgImg = [UIImage imageNamed:@"nav_menu_icon.png"];
UIButton *leftButton = [[UIButton alloc] initWithFrame: CGRectMake(x, y, bgImg.size.width, bgImg.size.width)];
viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];

还可以将“淡色”更改为“透明色”。

试试这个,可能会对您有所帮助

//解决您的框架问题

UIImage * bgImg = [UIImage imageNamed:@"nav_menu_icon.png"];
UIButton *leftButton = [[UIButton alloc] initWithFrame: CGRectMake(x, y, bgImg.size.width, bgImg.size.width)];
viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];

还可以将“淡色”更改为“透明色”。

您为它设置了淡色吗?您为它设置了淡色吗?这对我也很有用。谢谢,也为我工作过。谢谢