0

我使用自定义 UIViews 作为 navigationBarItem(就像 Facebook 在他们的 iOS 应用程序中那样)。

UIImageView *linkesMenu = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"187menu.png"]];
UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithCustomView:linkesMenu];

barItem.action = @selector(MenuSlider:);
self.navigationItem.leftBarButtonItem = barItem;

我尝试了这个和其他一些东西,但没有任何效果。

4

1 回答 1

0

尝试先将图像放入按钮中:

UIImage *theImage = [UIImage imageNamed:@"image.png"];
UIButton *theButton = [UIButton buttonWithType:UIButtonTypeCustom];
theButton.bounds = CGRectMake(0, 0, theImage.size.width, theImage.size.height);
[theButton setImage:theImage forState:UIControlStateNormal];
UIBarButtonItem *theBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:theButton];


[theButton addTarget:self action:@selector(MenuSlider:) forControlEvent:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = barItem;
于 2013-06-26T19:07:08.520 回答