我想创建一个UIBarButtonItem
看起来完全像这样的:
我怎样才能做到这一点?
UIImage *button30 = [[UIImage imageNamed:@"button_textured_30"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
[[UIBarButtonItem appearance] setBackgroundImage:button30 forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
使用它作为一种实用方法来为您的任何视图添加左栏按钮。进行明显的更改以获得右栏按钮。
+(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];
}
希望对您有所帮助。
创建一个自定义按钮并使用它,即;[self.navController.leftBarButtonItem = customButton];