Ios 无法更改按钮图片

Ios 无法更改按钮图片,ios,objective-c,uibutton,Ios,Objective C,Uibutton,我有3个按钮: *.h:(都是填充圆,这意味着它们是指定的) *.m: 和代码: AllButton.imageView.image =[UIImage imageNamed:@"list_top_icon_active-1.png"]; //image exists 而且它不会改变图像!从另一个角度看,我也这么做了,它们也起作用了——这到底是怎么回事 我甚至尝试设置不存在的图像: AllButton.imageView.image =[UIImage imageNamed:@"oisagio

我有3个按钮:

*.h:(都是填充圆,这意味着它们是指定的

*.m:

和代码:

AllButton.imageView.image =[UIImage imageNamed:@"list_top_icon_active-1.png"]; //image exists
而且它不会改变图像!从另一个角度看,我也这么做了,它们也起作用了——这到底是怎么回事

我甚至尝试设置不存在的图像:

AllButton.imageView.image =[UIImage imageNamed:@"oisagiowgiow.png"]; //image doesn't exist - but no errors or crashes
有人能帮我修一下吗

试试类似的方法

[AllButton setImage:[UIImage imageNamed:@"list_top_icon_active-1.png"] forState:UIControlStateNormal];
并确保您的按钮类型是自定义的

试试这个

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(40, 140, 240, 30);
[button setTitle:@"title" forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal];

应按以下方式将图像指定给UIButton:

[allButton setImage:[UIImage imageNamed:@"oisagiowgiow.png"] forState:UIControlStateNormal];

没有UIButtonTyperoundRect需要自定义使用名为setBackgroundImage或setImageYou是正确的,但为什么我的代码在其他控制器上工作?
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(40, 140, 240, 30);
[button setTitle:@"title" forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal];
[allButton setImage:[UIImage imageNamed:@"oisagiowgiow.png"] forState:UIControlStateNormal];