如何解决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:)];
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。