0

如何删除 dafult 按钮以将自定义按钮放置在导航栏中?目前的问题是我的自定义按钮超过了默认按钮。在此处输入图像描述

请看一下截图,它会更清楚。

我用以下代码得到这个:

- (void)viewDidLoad
{
    UIImage *menuImage = [UIImage imageNamed:@"barMenuButton.png"];
    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithImage:menuImage style:UIBarButtonItemStylePlain target:self action:@selector(ShowLeftMenu:)];
    [self.navigationItem setRightBarButtonItem:addButton];

}
4

2 回答 2

1

这将解决您的问题:

UIImage *menuImage = [UIImage imageNamed:@"barMenuButton.png"];

UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 100, 40);
[button setImage:menuImage forState:UIControlStateNormal];

UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithCustomView:button];
[addButton setAction:@selector(ShowLeftMenu:)];

[self.navigationItem setRightBarButtonItem:addButton];
于 2012-10-23T17:36:19.737 回答
0

您必须创建一个自定义视图并将其添加到栏按钮项,如本文所述本文还提供了一些有关创建自定义UIButtons.

于 2012-10-23T17:34:05.693 回答