0

我正在尝试将图像设置为 rightBarButtonItem。

我尝试通过两种方式做到这一点:

/* first way */
UIButton *button1 = [[UIButton alloc] init];
button1.frame=CGRectMake(0,0,105,30);
[button1 setBackgroundImage:[UIImage imageNamed: @"image.png"] forState:UIControlStateNormal];
[button1 addTarget:self action:@selector(rightBarButtonItemTapped) forControlEvents:UIControlEventTouchUpInside];

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button1];

/* second way */
UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"image"]
                                                                       style:UIBarButtonItemStyleBordered
                                                                      target:self
                                                                      action:@selector(rightBarButtonItemTapped)];

PS 当我点击导航栏的右侧时,我看到调用了 rightBarButtonItemTapped 方法。

4

1 回答 1

1

您可以使用属性检查器将图像设置为条形按钮。

在此处输入图像描述

于 2014-08-17T15:25:28.713 回答