0

我想创建一个UIBarButtonItem看起来完全像这样的:

我怎样才能做到这一点?

4

3 回答 3

1
UIImage *button30 = [[UIImage imageNamed:@"button_textured_30"]
    resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
[[UIBarButtonItem appearance] setBackgroundImage:button30 forState:UIControlStateNormal
    barMetrics:UIBarMetricsDefault];
于 2013-01-17T10:13:16.837 回答
1

使用它作为一种实用方法来为您的任何视图添加左栏按钮。进行明显的更改以获得右栏按钮。

+(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];
}

希望对您有所帮助。

于 2013-01-17T10:53:51.057 回答
0

创建一个自定义按钮并使用它,即;[self.navController.leftBarButtonItem = customButton];

于 2013-01-17T09:06:28.597 回答