1

我正在使用外观代理来设置 UIBarButtonItem 的背景图片:

UIImage *buttonBBI = [[UIImage imageNamed:@"bbi_texture.png"]
                       resizableImageWithCapInsets:UIEdgeInsetsMake(5, 4, 5, 4)];

这是bbi_texture@2x.png(视网膜) 在此处输入图像描述

但是按钮中出现了一个白条。知道可能是什么原因造成的吗?

在此处输入图像描述

4

2 回答 2

0

这就是我制作自定义 UIBarButton 的方式。非常适合我。

UIButton *postView = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 61, 30)];
[postView setTitle:@"Post" forState:UIControlStateNormal];
[postView addTarget:self action:@selector(showAddPost) forControlEvents:UIControlEventTouchUpInside];
[postView setBackgroundImage:[UIImage imageNamed:@"bbi_texture.png"] forState:UIControlStateNormal];
[postView setBackgroundImage:[UIImage imageNamed:@"bbi_texture.png"] forState:UIControlStateHighlighted];

UIBarButtonItem *postButton = [[UIBarButtonItem alloc] initWithCustomView:postView];
[self.navigationItem setRightBarButtonItem:postButton];
于 2013-05-23T06:35:09.057 回答
0

希望下面的工作正常

UIBarButtonItem *homeButton = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"Home"] style:UIBarButtonItemStyleBordered target:nil action:@selector(goHome:)];

 NSArray *leftBarButtonItems = [NSArray arrayWithObjects:homeButton,nil];

self.yourViewController.navigationItem.leftBarButtonItems = leftBarButtonItems;
于 2013-05-23T01:32:25.537 回答