我正在尝试将图像设置为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方法。
您可以使用属性检查器将图像设置为条形按钮。