无法更改按钮图片

时间:2013-10-31 06:43:23

标签: ios objective-c uibutton

我有3个按钮:

*。h :(所有都是填充圆圈,这意味着他们已分配

@property (strong, nonatomic) IBOutlet UIButton *AllButton;
@property (strong, nonatomic) IBOutlet UIButton *FavouritesButton;

* M:

@synthesize FavouritesButton;
@synthesize AllButton;

和代码:

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

任何人都可以帮我解决这个问题吗?

3 个答案:

答案 0 :(得分:1)

试试这个,

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];

答案 1 :(得分:0)

尝试类似

的内容
[AllButton setImage:[UIImage imageNamed:@"list_top_icon_active-1.png"] forState:UIControlStateNormal];

并确保您的按钮类型为自定义

答案 2 :(得分:0)

您应该通过以下方式将图像分配给UIButton:

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