UIBarButtonItem中的奇怪行

时间:2013-05-23 00:24:03

标签: ios objective-c cocoa-touch

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

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

这是bbi_texture@2x.png(视网膜) enter image description here

但是按钮上有一个白条。知道可能导致这种情况的原因吗?

enter image description here

2 个答案:

答案 0 :(得分: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;

答案 1 :(得分: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];