2012-07-10 95 views
0

我不能得到這段代碼,只是讓UIButton的圖像工作。錯誤消息總是說tempButt是UIView,它不會響應呼叫imageForState:
有人可以告訴我爲什麼以及如何正確地做到這一點?
最終我想將這張圖片與其他圖片進行比較,看它們是否相同。從[self.view viewWithTag:n]獲取UIButton時無法獲取UIButton圖像;

UIButton* tempButt = (UIButton*)[self.view viewWithTag:tagNum]; 
UIImage* tempImage = [tempButt imageForState:UIControlStateNormal]; 

回答

0

請確保您已設置圖像的背景圖像或圖片,如果你雖設置圖片爲背景圖片試試這個

UIImage * img = [btn backgroundImageForState:UIControlStateNormal]; 

您可以設置圖片作爲含量的不同而另一個圖像作爲背景這段代碼將得到背景圖片

0

是U確保ü已添加的按鈕作爲一個子視圖,以self.view(在廈門國際銀行或代碼),並設置其標記屬性由tagNum持有的價值?只是檢查EM一次..

我相信ü可能在上述情況之一出現了問題..

如果碰巧是一個按鈕,那麼我敢肯定,這兩種調用一個應該得到ü的按鈕圖像..

A按鈕具有兩個屬性圖像和backgorundImage ..

爲了得到圖像使用

tempButt.currentImage (or) [tempButt imageForState:UIControlStateNormal]; 

爲了得到背景圖片使用

tempButt.currentBackgroundImage 

請注意,imageForState方法僅如果u已設置圖像按鈕圖像工程..

希望這有助於!

+0

我真的很感謝你幫助我的努力。我檢查了你所說的一切,但沒有幫助。我不知道爲什麼...... – minjiera 2012-07-11 06:01:48