2013-11-09 19 views
0

由於我是新來的iOS編程,我受的意見網格創建光周期遊戲編程爲:通過編程開關的iOS

- (void)createGrid 
{ 
    float x=0,y=0; 

    for (int i=0; i<288; i+=16) 
    { 

     x = i + 16; 

     for (int j=0; j<288; j+=16) 
     { 

      y = j + 16; 

      UIView *panel = [[UIView alloc] initWithFrame:CGRectMake(x, y, 15, 15)]; 
      panel.backgroundColor = [UIColor purpleColor ]; 
      [self.view addSubview:panel];  
     } 
    } 

} 

現在我想改變的背景視圖之間切換點擊向上,向下,向左,向右按鈕,爲每個視圖提供顏色。

+0

表示你想通過點擊交換視圖? – Ganapathy

+0

hm..18x18 UIViews和所有紫色。開始使用-setTag方法,併爲網格中的每個UIView添加一個標籤,這樣當您使用按鈕上/下/左/右時,可以使用某種邏輯保留標籤的軌跡,並且您可以從在那裏更改該視圖的背景顏色。 – staticVoidMan

回答

0

你可以這樣說:

UIView *subview = self.view.subvies [i]; 
subview.backgroundColor = [UIColor redColor]; 

但是,如果規劃能有更多複雜的遊戲退房設計的遊戲引擎,而不是UIKit的。