2013-10-31 24 views
-3

我有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 

誰能幫助我解決這個問題?

+1

使用名爲set的屬性BackgroundImage或setImage – Tendulkar

回答

0

試着這麼做

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

,並確保您的按鈕類型是定製

+0

你是對的,但爲什麼我的代碼在其他控制器上工作? – Cheese

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

沒有UIButtonTypeRoundedRect需要自定義 –

0

您應該指定圖像的UIButton方式如下:

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