无法将图像设置为UINavigationBar的rightTabBarItem

问题描述 投票:0回答:1

我正在尝试将图像设置为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)];

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

ios ios7 uinavigationcontroller uinavigationbar rightbarbuttonitem
1个回答
1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.