UIView * myView = [[UIView alloc]initWithFrame:CGRectMake(320/2 – 200/2, 100, 200, 200)];//200*200的大棋盘
myView.backgroundColor = [UIColor redColor];
[self.window addSubview:myView];
for(int i = 0;i<100;i=i+2){
//i%10是求出每一行的0到9的位置,i/10是求出所在的行的位置,除以2是为了隔开1行颜色
UIView *insertView = [[UIView alloc]initWithFrame:CGRectMake((i%10+i/10%2)*20, i/10*20, 20, 20)];
insertView.backgroundColor = [UIColor blackColor];
[myView addSubview:insertView];
[insertView release];
}
[myView release];