我試圖創建一個按鈕,每次擊中它時都會更改我的UIView背景圖像。基本上我有一個數組中的3張圖像,每次按下「更改BG」時,我都要循環顯示。如何訪問當前的bg圖像?
我目前在我的viewDidLoad中使用self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_image.png"]];
來首先設置我的bg。
問題是,當我按下「更改BG」按鈕時,如何找出當前BG設置的內容?我已經嘗試使用if語句,如下所示:
if(self.view.backgroundColor == [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_image.png"]])
但它似乎並不奏效。我也嘗試創建一個局部變量UIColor * bg = self.view.backgroundColor,然後將其與bg == [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_image.png"]];
進行比較,但這也不起作用。
任何想法,將不勝感激。謝謝
就像@xhan說的。使用財產是一個好主意。 – Bonny 2012-01-17 08:11:14