UIBarBUttonItem图片

问题描述

| 我有一个带有3个按钮的编程工具栏(此处仅显示1个)。经过大量的Google搜索后,我可以设置一个漂亮的背景图片,但是现在我不知道该放在哪里
action: target:self action:@selector(pressButton3:)
方法代码。所以我有一个无法正常工作的按钮,彩色图像很好。我已经尝试了很多示例,如果按钮正常工作,则图像无效,反之亦然。请帮忙。
//Add buttons
UIImage *buttonImage = [UIImage imageNamed:@\"mapp.png\"];

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setimage:buttonImage forState:UIControlStatenormal];
button.frame = CGRectMake(0,buttonImage.size.width,buttonImage.size.height);

UIBarButtonItem *systemItem1 = [[UIBarButtonItem alloc] initWithCustomView:button];
[systemItem1 initWithBarButtonSystemItem:UIBarButtonItemStylePlain target:self action:@selector(pressButton1:)];

//add to array
 NSArray *items = [NSArray arrayWithObjects: systemItem1,nil];
    

解决方法

        如果您添加以下内容,我认为您的按钮应该可以正常工作:
[button addTarget:self action:@selector(pressButton1:) forControlEvents:UIControlEventTouchUpInside];
并删除该行:
[systemItem1 initWithBarButtonSystemItem:UIBarButtonItemStylePlain target:self action:@selector(pressButton1:)];