的UIBarButtonItem看起来坏在iOS6的

问题描述:

我使用导航栏我的应用程序。在iOS7,我的导航leftButtonItem图标显示正常(http://prntscr.com/2vaha7)。但在iOS6的,它看起来就像是:http://prntscr.com/2vafer的UIBarButtonItem看起来坏在iOS6的

我的代码:

_item2 = [[UINavigationItem alloc] init]; 

_item2.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"sliderMenu.png"] style:UIBarButtonItemStylePlain target:self action:@selector(revealMenu:)]; 

[self.navigationBar pushNavigationItem:_item2 animated:NO]; 

我怎样才能在iOS6的解决这个问题的视觉,而不是作品也未尝不可?

最好的问候,

Onder。

看看:http://www.raywenderlich.com/21703/user-interface-customization-in-ios-6

和:http://iosdevblog.com/2013/01/26/the-recommended-size-for-custom-uibarbuttonitem/

您需要为您的按钮创建一个自定义透明的背面图像,并将其设置为栏按钮为iOS 6的背景图像:

[[UIBarButtonItem appearance] setBackgroundImage:clearImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; 
[[UIBarButtonItem appearance] setBackgroundImage:clearImage forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault]; 

//编辑:我首先以为它是一个后退按钮,您需要像下面这样调整大小:

UIImage *buttonBack30 = [clearImage resizableImageWithCapInsets:UIEdgeInsetsMake(0, 10, 0, 6)]; 
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:buttonBack30 forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; 

我创建clearImage用下面的代码,但你完全可以创建任何颜色的34x60图像:

+ (UIImage *)imageWithColor:(UIColor *)color andSize:(CGRect)rect { 
// Create a 1 by 1 pixel context 
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0); 
[color setFill]; 
UIRectFill(rect); // Fill it with your color 
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

return image; 

}

UIImage *clearImage = [self imageWithColor:[UIColor clearColor] andSize:CGRectMake(0, 0, 34, 60)]; 

    [[UIBarButtonItem appearance] setBackgroundImage:backgroundImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; 
    [[UIBarButtonItem appearance] setBackgroundImage:backgroundImage forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault]; 
+0

谢谢你,它看起来像它要解决我的问题,所以我要在我的应用程序适用于整个ButtonItem代替iOS6的 –

+1

正确的作品你可以申请的,仅适用于iOS 6: 如果([[[的UIDevice currentDevice] systemVersion]的floatValue] Diwann