我正在尝试将图像设置为 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 方法。