我有一个带有UIToolbar的iOS应用,上面带有几个按钮。 其中之一,我根据日期以编程方式更改了图像,如下所示:

[_button setImage: [UIImage imageNamed: @"blah"]];

_button是一个IBOutlet。

在iPhone上,它工作正常,但是每次在iPad上运行该应用程序时,都会出现如下图所示的故障。 知道是什么原因造成的吗?

http://imagebin.org/306704

===============>>#1 票数:2

我们试试吧:

UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[closeButton setFrame: CGRectMake(0, 0, closeButtonFontSize.width, closeButtonFontSize.height)];
[closeButton.titleLabel setFont: font];
[closeButton setTitle: closeStr forState: UIControlStateNormal];
[closeButton setTitleColor: hoverColor forState: UIControlStateHighlighted];
[closeButton addTarget:self action:@selector(closePressed) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *closeBarButton = [[UIBarButtonItem alloc] initWithCustomView:closeButton];
//set this bar button to your toolbar

===============>>#2 票数:1

SetImage直接不适用于按钮,我们像这样设置按钮的图像和状态

[_button setImage:[UIImage imageNamed: @"blah"] forState:UIControlStateNormal];

带有图像的UIBarButtonItem

UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(action)];

否则您可以自定义barbuttonitem

===============>>#3 票数:1 已采纳

尝试这个

UIButton *btton = [UIButton buttonWithType:UIButtonTypeCustom];
[btton setFrame:CGRectMake(0, 0, 20, 20)];
[btton addTarget:self action:@selector(actionMenu:) forControlEvents:UIControlEventTouchUpInside];
 [btton setImage:[UIImage imageNamed:@“blah.png"] forState:UIControlStateNormal];

UIBarButtonItem * barbutton = [[UIBarButtonItem alloc] initWithCustomView:btton];

  ask by user591375 translate from so

未解决问题?本站智能推荐: