由于我是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 :(得分:0)
您是否检查了UICollectionView,UICollectionViewCell和UICollectionViewController课程?您的面板看起来可能是UICollectionViewCell
的子类。
答案 1 :(得分:0)
你可以这样做:
UIView *subview = self.view.subvies [i];
subview.backgroundColor = [UIColor redColor];
但是如果计划让更复杂的游戏检查设计的游戏引擎而不是UIKit。