- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
_window = [[UIWindowalloc] initWithFrame:[UIScreenmainScreen].bounds];
_window.backgroundColor = [UIColorwhiteColor];
[_windowmakeKeyAndVisible];
for (int j=0; j<15; j++) {
for (int i=0; i<10; i++) {
//创建视图
UIView *view = [[UIViewalloc] initWithFrame:CGRectMake(20*i,20*j, 20, 20)];
if ((i+j)%2 ==1) {
view.backgroundColor = [UIColorredColor];
}else {
view.backgroundColor = [UIColorblackColor];
}
[_window addSubview:view];
}
}
return YES;
}
这篇博客介绍了如何在iOS应用中创建一个棋盘界面。通过使用循环和条件判断,为15x10的网格分别设置红色和黑色背景,以形成棋盘效果。每个小方格是20x20像素大小,并且添加到窗口中。

被折叠的 条评论
为什么被折叠?



