我在我的应用程序中使用NavigationBar。在iOS7中,我的导航leftButtonItem图标看起来很好(http://prntscr.com/2vaha7)。但在iOS6上,它看起来是这样的:http://prntscr.com/2vafer。
我的代码:
_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中工作也很好?
诚挚的问候,
安德。
发布于 2014-02-24 00:17:08
看:http://www.raywenderlich.com/21703/user-interface-customization-in-ios-6
和:http://iosdevblog.com/2013/01/26/the-recommended-size-for-custom-uibarbuttonitem/
您将需要为您的按钮创建一个自定义透明的back图像,并将其设置为ios 6的bar按钮的背景图像:
[[UIBarButtonItem appearance] setBackgroundImage:clearImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackgroundImage:clearImage forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];//编辑:我首先认为它是一个back按钮,您需要这样做才能调整大小:
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];https://stackoverflow.com/questions/21976342
复制相似问题