2010-04-13 51 views
3

我以前有過這個問題,但能夠解決它到現在爲止,基本上我創建一個自定義的UIbutton設置它的圖像作爲一個uiimage,然後有一個標籤的按鈕,直到我實現下面的代碼現在失去它的標籤。我需要這個標籤,因爲它在後面的代碼中以編程方式設置。爲什麼我在按鈕中放置圖像時,UIButton.titleLabel.text會消失?

NSString *imageName = [NSString stringWithFormat:kNameOfButtonimage ]; 
      UIImage *image = [UIImage imageNamed:imageName]; 
      [button setImage:image forState:UIControlStateNormal ]; 

任何幫助你可以借出將mucho讚賞。

-nick

回答

5

我需要做一個:

[button setBackroundImage:image forState:UIControlStateNormal ]; 

,而不是這樣的:

[button setImage:image forState:UIControlStateNormal ]; 

;)

+0

我發現同樣適用於titleColor也即此 '[buttonTemp setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];' 而不是: 'buttonTemp.titleLabel.textColor = [UIColor blackColor];' – Ted 2012-10-26 11:53:02

相關問題