HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 无法为UIBarButtonItem设置图像大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试为我的UIBarButtonItem设置图像,但我无法做到这一点.我尝试了两次,在第一种情况下,我将我的图像放在正确的位置,但是当我点击按钮时没有任何反应(它应该弹出一个新窗口,但没有任何作用).我使用的是一段代码
UIImage *faceImage = [UIImage imagenamed:@"plus_button.png"];
    UIButton *face = [UIButton buttonWithType:UIButtonTypeCustom];
    face.bounds = CGRectMake( 0,faceImage.size.width,faceImage.size.height );
    [face setImage:faceImage forState:UIControlStateNormal];
   UIBarButtonItem *faceBtn = [[[UIBarButtonItem alloc] initWithCustomView:face]initWithImage:faceImage style:UIBarButtonItemStylePlain target:self action:@SELEctor(addProduct:)];

    self.navigationItem.leftBarButtonItem = faceBtn;

在第二种情况下,我在按钮上设置图像并且应该出现新窗口,但是不仅我想要的自定义图像,而且它还显示“边框”,看起来图像被放在认按钮的中心.显然我只想要我的图像,而不仅仅是我的图像.我在第二种情况下使用了一段代码

UIBarButtonItem *addButton = [[UIBarButtonItem alloc]initWithImage:faceImage style:UIBarStyleDefault target:self action:@SELEctor(addProduct:)];

    self.navigationItem.leftBarButtonItem = addButton;

请帮我解决问题,任何帮助都将不胜感激,谢谢!

解决方法

试试这个…改变它的方法,根据你的形象
UIButton *button1=[UIButton buttonWithType:UIButtonTypeCustom];
[button1 setFrame:CGRectMake(10.0,2.0,45.0,40.0)];
[button1 addTarget:self action:@SELEctor(showLeft:) forControlEvents:UIControlEventTouchUpInside];
[button1 setImage:[UIImage imagenamed:@"left-arrow-button.png"] forState:UIControlStateNormal];
UIBarButtonItem *button = [[UIBarButtonItem alloc]initWithCustomView:button1];
self.navigationItem.leftBarButtonItem = button;

大佬总结

以上是大佬教程为你收集整理的ios – 无法为UIBarButtonItem设置图像全部内容,希望文章能够帮你解决ios – 无法为UIBarButtonItem设置图像所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。