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

我尝试这样做2种方式:

/* 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)];


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

最佳答案

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

关于ios - 无法将图片设置为UINavigationBar的rightTabBarItem,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25350418/

10-15 05:01